octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #45835] inconsistent behaviour of eval inside


From: Rik
Subject: [Octave-bug-tracker] [bug #45835] inconsistent behaviour of eval inside anonymous functions
Date: Thu, 27 Aug 2015 21:17:39 +0000
User-agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)

Update of bug #45835 (project octave):

                  Status:                    None => Need Info              

    _______________________________________________________

Follow-up Comment #1:

Octave also waits to execute eval().


octave:1> f = @(t) eval ('t')
f =

@(t) eval ('t')

octave:2> eval ('t')
error: 't' undefined near line 1 column 1
octave:3> f (3)
error: 't' undefined near line 1 column 1
octave:4> t = 5
t =  5
octave:5> eval ('t')
t =  5
octave:6> f (3)
t =  5


In this case, 't' is a string and is not subject to variable replacement in
the anonymous function.

In your second case, t is not used as a string but as a variable.


f = @(t) eval (num2str (t))

is truly equivalent to

tmp = num2str (t)
eval (tmp)


One can verify that the eval is taking place because the return value of
num2str is a char variable, but the return value of the anonymous function f
is a double value which only happens because a string like "42" has been
eval'ed.


class (f (42))
ans = double


If you have access to Matlab, what does it return for the following?


clear all;
f = @(t) eval ('sin (t)');
f(1)




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?45835>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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