[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Nested Functions alternative?
From: |
Carlo de Falco |
Subject: |
Re: Nested Functions alternative? |
Date: |
Mon, 22 Jun 2009 08:37:50 +0200 |
On 21 Jun 2009, at 22:18, Jason Carver wrote:
Since Octave doesn't support nested functions, is there a suggested
alternative for closures of non-trivial method size?
For example, I want to do something like this:
function f = sophisticated_func_many_args(arg2,arg3,arg4)
function ans = sophisticated_func_one_arg(arg1)
#do something with args 1-4 for several lines
#set answer
end
f = @sophisticated_func_one_arg
end
one_arg_func = sophisticated_func_many_args(2,3,4)
result = built_in_library_call(one_arg_func)
maybe I'm missing the point here, but wouldn't
function f = sophisticated_func_many_args (arg1, arg2, arg3, arg4)
#do something with args 1-4 for several lines
#set answer
endfunction
result = built_in_library_call(@(arg1) sophisticated_func_many_args
(arg1,2,3,4))
do what you want?
This situation is particularly relevant when a library requires a
single-argument function passed in (eg~ ode45). Maybe I'm just
spoiled with python lately, but I don't even see the imperative
workaround for this anymore. What is the suggested alternative for
this pattern in Octave?
Cheers,
Carver
HTH,
c.