bugGNU Octave - Bugs: bug #53359, evalin overwrites ans in the...

 
 

bug #53359: evalin overwrites ans in the caller workspace

Submitted by:  Ceral Paquet <octavebugs>
Submitted on:  Fri 16 Mar 2018 12:37:21 PM UTC  
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Wont Fix Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  4.2.1 Operating System:  GNU/Linux

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Tue 20 Mar 2018 10:44:46 AM UTC, comment #3: 

No disagreement that it's bad form to use eval and "ans" especially together... but you know the savages do it ;)

One place it has a consequence is the clearvars function (#40095). It uses evalin to remove variables in the caller workspace but ends up creating (or overwriting) "ans" as a side-effect.

Ceral Paquet <octavebugs>
Fri 16 Mar 2018 06:30:34 PM UTC, comment #2: 

This is very similar to bug #46397.

>> 11
ans =  11
>> x = eval ('12')
x =  12
>> ans
ans =  12

In that bug report, Rik expressed the opinion that the Octave behavior makes more sense. Since the code in the eval expression may have other side effect that do affect the calling environment, why should updating the 'ans' variable be any different?

I personally think that code shouldn't rely on the value of 'ans' at all, so I agree that this is not worth fixing.

Mike Miller <mtmiller>
Project Administrator
Fri 16 Mar 2018 01:48:10 PM UTC, comment #1: 

Just to confirm the case where evalin is not assigned.

function test_evalin()
evalin('caller','sqrt(11);');

MATLAB

>> ans=1; test_evalin; ans
ans =
    3.3166

Ceral Paquet <octavebugs>
Fri 16 Mar 2018 12:37:21 PM UTC, original submission:  

Consider the following function:

function test_evalin()
x = evalin('caller','sqrt(11);');

Since the result of evalin is assigned within the local scope, it should not be left as "ans" in the caller's workspace. On the other hand, if it is not assigned in the local scope, then it should be left in the caller in "ans".

Currently Octave does the latter for both cases.

MATLAB

>> ans=1; test_evalin; ans
ans =
     1

Octave

>> ans=1; test_evalin; ans
ans =  3.3166

Ceral Paquet <octavebugs>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by octavebugs (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-03-16 mtmiller StatusNone => Wont Fix
        Open/ClosedOpen => Closed

    Back to the top


    Powered by Savane 3.7