[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: a puzzle...
From: |
Ben Abbott |
Subject: |
Re: a puzzle... |
Date: |
Sat, 04 Feb 2012 10:17:28 -0500 |
On Feb 4, 2012, at 4:07 AM, Muhali wrote:
> ok, here is a real puzzle.
>
> Put into a new directory these 4 files:
>
> -----------------
> # foo.m
> global gfun
> gfun = @fC ;
> y = fA(e)
> -----------------
> # fA.m
> function y = fA (x, f)
> global gfun
> if nargin < 2
> y = fA(x, gfun) ;
> else
> w = feval(f, x) ;
> y = feval("fB", w) ; # <--- this is crucial
> endif
> endfunction
> -----------------
> # fB.m
> function y = fB (x) y = x ; endfunction
> -----------------
> # fC.m
> function y = fC (x) y = x ; endfunction
> -----------------
>
> From that direcotry, assuming '.' is in the path, you get:
>
> %> octave -q foo.m
> y = 2.7183
>
> Nice. But when in fA.m '"fB"' is replaced by '@fB' one gets
>
> %> octave -q foo.m
> error: `w' undefined near line 7 column 22
> error: evaluating argument list element number 2
> error: called from:
> error: /home/muhali/fA.m at line 7, column 9
> error: /home/muhali/fA.m at line 4, column 9
> error: /home/muhali/foo.m at line 3, column 3
>
> Why is that?
>
> M.
I ran your example from Octave's command line. With ..,
y = feval ("fB", w);
... and with ...
y = feval (@fB, w);
... I obtained the same result.
y = 2.7183
I'm running a recent tip.
Did you include the single-quotes, like below ?
y = feval ('@fB', w);
What version of Octave are you running ? Do you get the same result from
Octave's command line as when you run from your shell's prompt.
Ben
- a puzzle..., Muhali, 2012/02/04
- Re: a puzzle...,
Ben Abbott <=
- Re: a puzzle..., Muhali, 2012/02/04
- Re: a puzzle..., Ben Abbott, 2012/02/04
- Re: a puzzle..., Ben Abbott, 2012/02/04
- Re: a puzzle..., Muhali, 2012/02/04
- Re: a puzzle..., Ben Abbott, 2012/02/04
- Re: a puzzle..., Muhali, 2012/02/04
- Re: a puzzle..., Ben Abbott, 2012/02/05
- Re: a puzzle..., Martin Helm, 2012/02/05
- Re: a puzzle..., Martin Helm, 2012/02/04
Message not available