[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
anonymous functions?
From: |
Olaf Till |
Subject: |
anonymous functions? |
Date: |
Thu, 16 Nov 2006 16:09:13 +0100 |
User-agent: |
Mutt/1.5.9i |
Hi,
I just tried to use anonymous functions, but they do not seem to work
as expected. To demonstrate this, I tried the following on Octave
2.1.69 and 2.1.73:
defined the following two functins in respective files:
function y = tttf (a, b)
y = a + b;
and
function ret = tttf2 (F, x)
ret = feval (F, x);
Then,
octave:1> b = 2
b = 2
octave:2> tttf2 (@ (x) tttf (x, b), 3)
error: `b' undefined near line 2 column 23
error: evaluating argument list element number 2
error: called from `?unknown?'
error: evaluating assignment expression near line 2, column 7
error: called from `tttf2' in file `/home/olaf/devel/octave/m/tttf2.m'
octave:2>
Matlab returns 5 as expected.
Octaves anonymous function seems to take the 'b' 'literally', not its
value. (The same applied to function handles used in the body of an
anonymous function.)
What is going on? Is this a bug? Is there a higher octave version with
different behavior?
If I want to make a wrapper function which changes an argument
representing a function to be called, anonymous functions are probably
the only clean way to go.
Regards,
Olaf
- anonymous functions?,
Olaf Till <=