On 12/18/19 2:53 PM, Burgers, A.R. (Teun) wrote:
Op 18-12-2019 om 18:51 schreef John W. Eaton:
On 12/18/19 12:37 PM, John W. Eaton wrote:
On 12/18/19 10:11 AM, Juan Pablo Carbajal wrote:
These are the results
Thanks.
after I modified f1 and f2 (attached; Matlab
2019a doesn't accept declaration of persistent and initialization in
the same line)
Oops.
It looks like the private function is loaded the first time it is
used and then also cleared by the "clear functions" command. But
then it also remains available through the handle. So I'm wondering
whether the handle should retain a reference to the function and
"clear functions" should only remove it from thh symbol table, or
whether it should be reloaded if it becomes invalid. I'm thinking
the first option would be best unless someone knows of a reason to
do otherwise.
Here's another test to run to see whether keeping a reference to the
function in the handle will be compatible with Matlab behavior:
unpack the attached file and execute the following commands in Matlab:
cd fh-bug
fh = f1
fh() %% should display "foo-i-hithere: 1"
f2 %% should display "foo-i-hithere: 2"
clear functions %% what will happen with persistent value in "gg"?
fh() %% does this display "... 3" or "... 1"?
f2 %% does this display "... 1" or "... 2" or ?
jwe
I get this:
>> version
ans = '9.5.0.1049112 (R2018b) Update 3'
>> cd fh-bug
>> fh = f1
fh = function_handle with value: @gg
>> fh()
foo-i-hithere: 1
>> f2
foo-i-hithere: 2
>> clear functions
>> fh()
foo-i-hithere: 1
>> f2
foo-i-hithere: 2
Thanks.
So it looks like "clear functions" also clears functions that are
referenced by function handles, but then those handles are able to
reload them from their initial location, even if that is no longer in
the search path (as shown by the first tests I posted earlier). Does
that seem like the correct interpretation? To be sure, does the above
work the same if you do
cd fh-bug
fh = f1
fh()
f2
cd ..
clear functions
fh() %% does this still work?
f2 %% expect error here as f2 is no longer in the search path
jwe