bugGNU Octave - Bugs: bug #45682, str2func should accept '@(x) x^2'...

 
 

bug #45682: str2func should accept '@(x) x^2' for matlab compatability

Submitter:  Jeff Fessler <professler>
Submitted:  Mon 03 Aug 2015 06:50:37 PM UTC
   
 
Category:  Octave Function Severity:  1 - Wish
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Jeff Fessler Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 23 Sep 2015 09:40:39 AM UTC, comment #4: 

Fixed on the development branch in this cset (http://hg.savannah.gnu.org/hgweb/octave/rev/df7d34a1c7e6).

Rik <rik5>
Group administrator
Mon 10 Aug 2015 03:42:56 AM UTC, comment #3: 

In the meantime, I changed the documentation on the stable branch to note that anonymous functions are not supported and that the preferred workaround is


func = eval (str);


The changeset for that is here http://hg.savannah.gnu.org/hgweb/octave/rev/8fcbb55745ef.

On the development branch, I added a check for anonymous functions and it issues an error now (http://hg.savannah.gnu.org/hgweb/octave/rev/82712ed1be68).

This is just a partial fix until someone can figure out how to essentiall call 'eval (str)' from the C++ code in ov-fcn-handle.cc.

Rik <rik5>
Group administrator
Mon 03 Aug 2015 08:27:14 PM UTC, comment #2: 

yes i think that is all that is needed.
if str2func were an m-file i would have offered a fix but it is a built-in function and modifying those is beyond my know how...

Jeff Fessler <professler>
Mon 03 Aug 2015 07:11:56 PM UTC, comment #1: 

Thanks for the report. So basically, if str starts with "@", then str2func(str) returns exactly the same thing as eval(str)? This looks pretty simple to add to Octave.

Mike Miller <mtmiller>
Group Member
Mon 03 Aug 2015 06:50:37 PM UTC, original submission:  

Matlab is going to phase out inline in future releases
http://www.mathworks.com/help/matlab/ref/inline.html

But there are still situations where one must create a function from a string and "strfunc" is the way to do that.

In Matlab, the following code bit makes a useful function handle:


sqr = str2func('@(x) x^2')


whereas octave (3.8.2) returns the following error message:


error: @@(x) x^2: no function and no method found


For compatibility it would be useful if Octave also supported that usage of str2func().


Jeff Fessler <professler>

 

(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

Digest:
   bug dependencies.

 

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

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-02-02 mtmiller Dependencies- bugs #47046 is dependent
    2015-09-23 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2015-08-03 mtmiller Severity3 - Normal 1 - Wish
        StatusNone Confirmed
        Release3.8.2 dev

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code