[Top][All Lists]

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

local functions in file

From: John W. Eaton
Subject: local functions in file
Date: Thu, 1 Aug 2002 17:40:01 -0500

On  1-Aug-2002, Victor Eijkhout <address@hidden> wrote:

| It seems that matlab interprets multiple functions in a file as "from 
| the second one on are local functions to the file". I've used this a 
| couple of times. It encourages modular programming.
| Octave doesn't seem to be compatible with that, right?

No, not yet.  But I started thinking about how to implement it, and it
seems to me that if we are going to allow nested functions, that it
should be possible to nest them to an arbitrary depth.  For example:

  function f1 (..)
    function f2 (..)
      function f3 (...)
      function f4 (...)

As I see it, f3 and f4 would only be visible in f2, and f2 would only
be visible in f1 (although I suppose it would also make some sense to
be able to call f2 recursively from f3 or f4).

However, I think Matlab does not require (or even allow?) an end token
to end a function definition, so on seeing f3 (or f4) above, it would
be impossible to tell immediately whether f3 (or f4) is local to f2
(meaning that it would not be visible to f1) or simply local to f1,
the same as f2.

To also allow

  function f1 (...)

  function f2 (...)

  function f3 (...)


to nest f2 and f3 inside f1 the same as Matlab apparently works, it
will more work to implement the arbitrarily deep nesting because on
seeing f3 we would have to wait to see whether there are some end or
endfunction keywords that match the function keywords so that we
could patch up the symbol tables and put the nested functions in the
right places.

So, the question is whether it is worth the extra trouble.



Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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