octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #59344] Run source('filename.m', 'caller') and


From: Glite
Subject: [Octave-bug-tracker] [bug #59344] Run source('filename.m', 'caller') and Get a 'base' Context
Date: Sat, 31 Oct 2020 03:15:40 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36

Follow-up Comment #2, bug #59344 (project octave):

You are right.
I change _b.m_ to:

function o=b(i)
    i+=3;
    callit
    source('callit.m','base')
    source('callit.m','caller')
    function o=d(i)
        source('callit.m','base')
        source('callit.m','caller')
    endfunction
    d(i)
endfunction

And the result is:

>> b(3)
here, i=6
here, i=1
here, i=1
here, i=1
here, i=6

It proves that the context changes and the behavior is correct.
Many thanks!
[comment #1 comment #1:]
> This is correct behavior.  When you execute "b(3)" the "caller" context is
the same as the "base" context since "b(3)" is called from the Octave prompt. 
Since they are the same context, they must return the same results.
> 
> Also, there is no change to the variable "i" because the script callit.m
makes no assignment to it.
> 
> If I modify callit.m to
> 
> 
> i = i + 1;
> a(i)
> 
> 
> and then execute
> 
> 
> octave:7> i = 1
> i = 1
> octave:8> b(3)
> here, i=7
> here, i=2
> here, i=3
> octave:9> i
> i = 3
> 
> 
> you can see that variables are changed in the base and caller context.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?59344>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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