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

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

[Octave-bug-tracker] [bug #60845] Nested functions variable scope


From: José Matos
Subject: [Octave-bug-tracker] [bug #60845] Nested functions variable scope
Date: Mon, 28 Jun 2021 15:54:32 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0

URL:
  <https://savannah.gnu.org/bugs/?60845>

                 Summary: Nested functions variable scope
                 Project: GNU Octave
            Submitted by: jamatos
            Submitted on: Mon 28 Jun 2021 07:54:30 PM UTC
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Incorrect Result
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
                 Release: dev
         Discussion Lock: Any
        Operating System: GNU/Linux

    _______________________________________________________

Details:

After some discussion in the maintainers channel of discourse I arrived to
this function:


function mainfcn2 (varargin)

  [Ahandle, static, fcn_handle] = checkInput(varargin{:});  # A boolean
variable
  output = fcn_handle ()  # executed nested function

  function [Ahandle, static, fcn_handle] = checkInput(varargin)
    %% initialize

    Ahandle = true;
    static = false;
    fcn_handle = @nestfcn;  # get a handle to nested function
  end

  function r = nestfcn ()
    if (islogical(Ahandle))
      disp("Success.")
    else
      fprintf("Something went wrong: Ahandle is a %s\n", class(Ahandle))
    end
    r = 1;
  end
end


Calling this function we get:

>> mainfcn2
Something went wrong: Ahandle is a function_handle
output = 1


If the scope was correct I would expect for Ahandle to be a logical value.
Instead, in this case, it gets the value of fcn_handle.

The original issue was using the nleigs package but I think that this is a
minimal example.




    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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