octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: need function handle test run in Matlab


From: John W. Eaton
Subject: Re: need function handle test run in Matlab
Date: Sun, 17 Mar 2019 11:17:26 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1

On 3/16/19 9:51 PM, Nicholas Jankowski wrote:
diary attached.  Matlab 2018b

>    afh = anonfcn (13)
>
>    afh =
>
>        @(s)eval(s)
>
>     afh ('a')
>
>     Undefined function or variable 'a'.
>
>    afh ('b')
>
>     Undefined function or variable 'b'.
>
>    nfh = nestfcn (42)
>
>    nfh =
>
>        @nestfcn/nst
>
>    nfh ('a')
>
>     ans =
>
>        42
>
>     nfh ('b')
>
>     ans =
>
>        16     2     3    13
>         5    11    10     8
>         9     7     6    12
>         4    14    15     1


Thanks.

So even though anonymous functions can capture values from the surrounding context, they are not equivalent to nested functions, which apparently have full access to the parent workspaces even when the variables are not explicitly referenced. I was hoping they would be equivalent (then the internal representation could be essentially identical; the only difference would be the syntax for parsing) but half expecting that they would be different because anonymous functions came well before nested functions. I believe Octave gets this behavior right but there is room for improvement in thm implementation.

jwe



reply via email to

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