bugGNU Octave - Bugs: bug #40938, interaction among eval, anonymous...

 
 

bug #40938: interaction among eval, anonymous function, and functions

Submitted by:  Felipe G. Nievinski <fgnievinski>
Submitted on:  Tue 17 Dec 2013 02:19:29 PM UTC  
 
Category: InterpreterSeverity: 2 - Minor
Priority: 1 - LaterItem Group: Matlab Compatibility
Status: ConfirmedAssigned to: None
Originator Name: Open/Closed: Open
Release: devOperating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Fri 25 Nov 2016 10:43:38 PM UTC, comment #2:

This behavior is still the same in Octave 4.2.0.

Hartmut <hardy>
Mon 29 Dec 2014 03:58:52 AM UTC, comment #1:

Confirmed. My guess is that Matlab is treating the anonymous function as a nested function, in which case it has access to the enclosing function's variables. Octave is probably treating this as a subfunction, in which case the scope does not include the caller's variables.

This sort of esoteric compatibility is a low priority and I've marked the bug as such.

Rik <rik5>
Project Administrator
Tue 17 Dec 2013 02:19:29 PM UTC, original submission:

This works in Matlab but doesn't in Octave:

function doit_bad ()
pi2 = pi; get2 = @(var) eval([var,'2']); get2('pi')
end

In the base workspace (i.e., entered in the terminal), that line statement doesn't work in Matlab nor in Octave.

In contrast, this version works in all combinations of Matlab/Octave and within-function/base-workspace:

function doit_good ()
pi2 = pi; get2 = @(var) evalin('caller', [var,'2']); get2('pi')
end

So it seems there's some interaction among eval, anonymous function, and functions.

Felipe G. Nievinski <fgnievinski>

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #29987:  doit_good.m added by fgnievinski (99B - text/plain)
file #29988:  doit_bad.m added by fgnievinski (86B - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by hardy (Posted a comment)
  • -unavailable- added by mtmiller (Updated the item)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by fgnievinski (Submitted the item)
  •  

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

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 6 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 31 Mar 2016 05:31:28 AM UTCmtmillerSeverity3 - Normal=>2 - Minor
      Operating SystemMicrosoft Windows=>Any
    Mon 29 Dec 2014 03:58:52 AM UTCrik5Priority5 - Normal=>1 - Later
      StatusNone=>Confirmed
    Tue 17 Dec 2013 02:19:29 PM UTCfgnievinskiAttached File-=>Added doit_good.m, #29987
      Attached File-=>Added doit_bad.m, #29988

    Back to the top


    Powered by Savane 3.1-cleanup1