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:19:01 -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 4:14 PM, John W. Eaton wrote:
On 1/29/19 4:01 PM, Andrew Janke wrote:
 > In Matlab, statements (including assignment) and compound expressions
 > (multiple expressions joined by semicolons or commas) are allowed in
 > eval. All your examples work.

Thanks.

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

Does this appear to be a restriction on parsing or evaluation?  In other words, does something like

   x = eval ('y = 1')

fail to parse the assignment statement or does it perform the assignment to Y and then fail to assign anything to X because (as I remember anyway) assignments in Matlab are statements and do not produce values.

Similarly, if you try

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

does the error happen when parsing the for loop statement or after the loop is executed (no value to assign)?

jwe

IIRC, the error happens at parse time, and eval balks at evaluating that code, giving you some sort of syntax error before any of it is evaluated.

Cheers,
Andrew



reply via email to

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