octave-maintainers
[Top][All Lists]
Advanced

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

Closures behaviour


From: CdeMills
Subject: Closures behaviour
Date: Fri, 26 Feb 2021 11:43:22 -0600 (CST)

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 ?

Regards

Pascal



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-Maintainers-f1638794.html



reply via email to

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