str2func

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

str2func

kingcrimson

Hi,

In the development branch str2func works with any string

>> f = str2func ("_5yVNhWVJWJn47RKnzxPsyb_")
f = @_5yVNhWVJWJn47RKnzxPsyb_

while in the stable release it returns an error if the string does not name an existing function

>> f = str2func ("_5yVNhWVJWJn47RKnzxPsyb_")
error: @_5yVNhWVJWJn47RKnzxPsyb_: no function and no method found

Is this intended, or is it a bug?

If it is intended, there are a few places where str2func is used to
check whether a string is the name of a function (for example ode45, ode15i, ...)
which should be fixed.

If this is not intended I'll submit a bug

c.




Reply | Threaded
Open this post in threaded view
|

Re: str2func

John W. Eaton
Administrator
On 3/13/19 1:42 AM, c. wrote:

>
> Hi,
>
> In the development branch str2func works with any string
>
>>> f = str2func ("_5yVNhWVJWJn47RKnzxPsyb_")
> f = @_5yVNhWVJWJn47RKnzxPsyb_
>
> while in the stable release it returns an error if the string does not name an existing function
>
>>> f = str2func ("_5yVNhWVJWJn47RKnzxPsyb_")
> error: @_5yVNhWVJWJn47RKnzxPsyb_: no function and no method found
>
> Is this intended, or is it a bug?
>
> If it is intended, there are a few places where str2func is used to
> check whether a string is the name of a function (for example ode45, ode15i, ...)
> which should be fixed.
>
> If this is not intended I'll submit a bug

It's intentional, for compatibility with Matlab.  There are a few bug
reports about it.  But I was fixing a different bug when I also fixed
the problem with str2func.

https://savannah.gnu.org/bugs/?func=detailitem&item_id=52568
https://savannah.gnu.org/bugs/?func=detailitem&item_id=31821

Why do you need to check?

Also, I would strongly recommend that people use function handles, not
simple names in character strings.

jwe




Reply | Threaded
Open this post in threaded view
|

Re: str2func

kingcrimson


> On 13 Mar 2019, at 07:09, John W. Eaton <[hidden email]> wrote:
>
> It's intentional, for compatibility with Matlab.  There are a few bug reports about it.  But I was fixing a different bug when I also fixed the problem with str2func.
>
> https://savannah.gnu.org/bugs/?func=detailitem&item_id=52568
> https://savannah.gnu.org/bugs/?func=detailitem&item_id=31821
>
> Why do you need to check?
indeed there is no real need to check but there are currently BIST tests
that expect this to be checked

> Also, I would strongly recommend that people use function handles, not simple names in character strings.
unfortunately that is needed for compatibility

> jwe
c.
Reply | Threaded
Open this post in threaded view
|

Re: str2func

John W. Eaton
Administrator
On 3/13/19 3:11 AM, [hidden email] wrote:

>
>
>> On 13 Mar 2019, at 07:09, John W. Eaton <[hidden email]> wrote:
>>
>> It's intentional, for compatibility with Matlab.  There are a few bug reports about it.  But I was fixing a different bug when I also fixed the problem with str2func.
>>
>> https://savannah.gnu.org/bugs/?func=detailitem&item_id=52568
>> https://savannah.gnu.org/bugs/?func=detailitem&item_id=31821
>>
>> Why do you need to check?
> indeed there is no real need to check but there are currently BIST tests
> that expect this to be checked
>
>> Also, I would strongly recommend that people use function handles, not simple names in character strings.
> unfortunately that is needed for compatibility

For now I checked in the following change that disables the BIST and
also notes a possible way to check whether the handle references a valid
function:

http://hg.savannah.gnu.org/hgweb/octave/rev/6bd408bde569

jwe