help-octave
[Top][All Lists]
Advanced

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

a puzzle...


From: Muhali
Subject: a puzzle...
Date: Sat, 4 Feb 2012 01:07:53 -0800 (PST)

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.

--
View this message in context: 
http://octave.1599824.n4.nabble.com/a-puzzle-tp4356700p4356700.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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