octave-maintainers
[Top][All Lists]
Advanced

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

Re: Closures behaviour


From: John W. Eaton
Subject: Re: Closures behaviour
Date: Fri, 26 Feb 2021 13:58:47 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1

On 2/26/21 12:43 PM, CdeMills wrote:
Hello,

I had to revive some old code. Since I use more and more Python, I wanted to
use closure mechanisms to keep the computation cleaner.

So I started refactoring the code, creating a main function which returns a
struct with a few function pointers. Those function pointers are initialized
to sub-funcs of the main function. According to MatLAB doc, the behavior is
that accessing the variable name in the subfunc has the effect of reading
the actual value from the parent environment.

I tested a very small example from
https://research.wmz.ninja/articles/2017/05/closures-in-matlab.html which
works in Octave 6.2. Now, on my code, I noticed that only a small number of
variables from the parent is accessible from the innermost context. The most
basic symptom is that the number of variables returned by "who" shrinks in
the internal functions.

I also tried under MatLAB 2018b, and all variables initialized before the
first function definition in the parent function are shared with all its
children.
Is this some well-known behavior which will be aligned on MatLAB in the long
run ?

Handles to nested functions are expected to work in a way that is compatible with Matlab. So if they don't, please file a bug report with sufficient information for someone to reproduce the problem.

jwe




reply via email to

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