octave-maintainers
[Top][All Lists]
Advanced

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

Re: Nested functions, documented?


From: David Grundberg
Subject: Re: Nested functions, documented?
Date: Sun, 27 Feb 2011 12:13:16 +0100
User-agent: Thunderbird 2.0.0.24 (X11/20101027)

Jordi GutiƩrrez Hermoso skrev:
> I see that David Grundberg submitted a patch in mid 2009 for nested
> functions, but I don't see the manual or anything else mention them. I
> don't really understand the limitations described therein. Since I'm
> updating the FAQ, what should be mentioned in the part where it talks
> about differences with nested functions between Matlab and Octave?

Nested functions are not supported in Octave.  They are functions that
appear inside the body of a function:

function my_primary_function ()
  function my_nested_function ()
     function my_nested_nested_function ()
     endfunction
  endfunction
endfunction
function my_subfunction ()
endfunction

The scoping rules are different from primary/sub functions, in that
nested functions can access the outer functions' variables.  This is
called textual scoping in programming language theory jargon.

But what Octave currently does is reinterpret the nested functions to
mean this:

function my_primary_function ()
endfunction
function my_nested_function ()
endfunction
function my_nested_nested_function ()
endfunction
function my_subfunction ()
endfunction

And the textual scoping is simply missing.  This could cause subtle or
hard to understand bugs if you run code that assume textual scoping.

Grundberg


reply via email to

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