help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: anonymous functions?


From: David Bateman
Subject: Re: anonymous functions?
Date: Thu, 16 Nov 2006 16:24:29 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

Olaf Till wrote:
> 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
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
>
>   

In a recent CVS of octave (and probably back to 2.9.8)

octave:1> function y = tttf (a, b), y = a + b; endfunction
octave:2> function ret = tttf2 (F, x), ret = feval (F, x); endfunction
octave:3> b = 2;
octave:4> tttf2 (@ (x) tttf (x, b), 3)
ans =  5
octave:5> ver
----------------------------------------------------------------------
GNU Octave Version 2.9.9+
GNU Octave License: GNU General Public License, Version 2
Operating System: Linux 2.6.12-27mdk-i686-up-4GB #1 Tue Sep 26 12:41:29
MDT 2006 i686
----------------------------------------------------------------------

So this is fixed..

D.


-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



reply via email to

[Prev in Thread] Current Thread [Next in Thread]