help-octave
[Top][All Lists]
Advanced

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

nested functions?


From: Vic Norton
Subject: nested functions?
Date: Tue, 18 Feb 2014 12:50:26 -0500

According to <http://www.gnu.org/software/octave/NEWS-3.8.html>
Octave now supports nested functions with scoping rules that are
compatible with Matlab.

Why then does
     1;
     function outerfunc()
       global printhello = 1;
       nested1();
       function nested1()
         global printhello;
         if printhello
           printf("hello world\n");
         else
           printf("goodbye world\n");
         endif
       endfunction
     endfunction
     outerfunc();

produce the error message

octave-cli-3.8.0> test2
parse error near line 11 of file 
/Users/vic/Norton/Programming/octave/m/tests/test2.m

  nested functions not implemented in this context

>>>   function nested1()
             ^

when
     1;
     function outerfunc()
       global printhello = 1;
       nested1();
     endfunction
       function nested1()
         global printhello;
         if printhello
           printf("hello world\n");
         else
           printf("goodbye world\n");
         endif
       endfunction
     outerfunc();

produces

octave-cli-3.8.0> test3
hello world



reply via email to

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