[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #39257] handles to nested functions are not ye
From: |
Marshall |
Subject: |
[Octave-bug-tracker] [bug #39257] handles to nested functions are not yet supported |
Date: |
Wed, 4 Apr 2018 11:19:24 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0 |
Follow-up Comment #22, bug #39257 (project octave):
In Matlab comment #20 results in
fh1 =
function_handle with value:
@foo/nest
fh2 =
function_handle with value:
@foo/nest
z =
1
z =
2
z =
2
z =
3
fh3 =
function_handle with value:
@foo/nest
z =
1
z =
4
z =
4
z =
5
This is the behavior I would expect: all accessing the same persistent memory
space.
For comment #19:
ans =
1 2 4
ans =
1 2 4
ans =
1 2 4
ans =
function_handle with value:
@foo/nest
ans =
1 2 4
ans =
1 2 4
ans =
1 2 4
This one surprised me, but makes sense after thinking about it. Each @nest
function handle points to the same function with the same memory space. That
memory space is static after returning from foo(). Calling the middle foo
doesn't change the memory space of the prior function. However this:
[fh1, fh2, fh3] = foo (2);
fh1 (1)
fh2 (1)
fh3 (1)
[fh4, fh5, fh6] = foo (20);
fh1 (1)
fh2 (1)
fh3 (1)
fh4 (1)
fh5 (1)
fh6 (1)
results in
ans =
1 2 4
ans =
1 2 4
ans =
1 2 4
ans =
1 2 4
ans =
1 2 4
ans =
1 2 4
ans =
1 20 4
ans =
1 20 4
ans =
1 20 4
This shows that two separate functions calls establish a new memory space
(because they are not persistent variable), and the anonymous functions there
refer to the memory space of the function in which they were created. At least
that is how I understand it.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?39257>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/