octave-maintainers
[Top][All Lists]
Advanced

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

Re: Questions about eval


From: Andrew Janke
Subject: Re: Questions about eval
Date: Tue, 29 Jan 2019 16:01:44 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Thunderbird/60.4.0



On 1/29/19 3:53 PM, John W. Eaton wrote:
I noticed that Matlab's documentation for eval no longer mentions the form

   eval (try_code, catch_code)

to evaluate the "catch_code" if "try_code" throws an error.  Should we also deprecate this feature in Octave?

Does Matlab restrict the code to be evaluated to be a single expression, or are statements and multiple expressions allowed?  For example, what happens for the following in current Matlab versions?

   eval ('x = 2+2')

   eval ('1+1, pi')

   eval ('for i = 1:3, i, end')

In Octave, all of these work.  If Matlab restricts the argument of eval to be a single expression (not a statement) then should we also impose that limitation?  It might simplify the implementation somewhat if we did not have to handle arbitrary code.

Thanks,

jwe

In Matlab, statements (including assignment) and compound expressions (multiple expressions joined by semicolons or commas) are allowed in eval. All your examples work.

If you use the output-capturing form `x = eval(expr)` then it needs to be a single non-compound, non-assignment-statement expression.

Cheers,
Andrew



reply via email to

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