[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: nested functions?
From: |
Vic Norton |
Subject: |
Re: nested functions? |
Date: |
Tue, 18 Feb 2014 14:29:55 -0500 |
On Feb 18, 2014, at 1:21 PM, Mike Miller <address@hidden> wrote:
> On Tue, Feb 18, 2014 at 12:50:26 -0500, Vic Norton wrote:
>> Octave now supports nested functions with scoping rules that are
>> compatible with Matlab.
>>
>> Why then does
>> [...example...]
>> 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
>
> I get the same parse error with your example. If I convert it to a
> function file named outerfunc.m and call outerfunc from the shell,
> then it works as you intended.
>
> octave:1> outerfunc
> hello world
>
> Does the test2.m example script run as you expect in Matlab?
>
> --
> mike
I haven't used Matlab for many years, Mike. I wouldn't know. But this is
becoming interesting.
The file "outerfunc.m" consisting of
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
produces the "nested functions not implemented in this context" error
message in Octave 3.8.0. However, if you comment out the "1;" line, it
works fine:
octave-cli-3.8.0> outerfunc
hello world
octave-cli-3.8.0> global printhello
octave-cli-3.8.0> printhello = 0;
octave-cli-3.8.0> outerfunc
goodbye world
It would be interesting to see how this file works in Matlab. I don't
particularly like the Octave behavior.
Regards,
Vic
- nested functions?, Vic Norton, 2014/02/18
- Re: nested functions?, Mike Miller, 2014/02/18
- Re: nested functions?,
Vic Norton <=
- Re: nested functions?, Mike Miller, 2014/02/18
- Re: nested functions?, Benjamin Abbott, 2014/02/18
- Re: nested functions?, Mike Miller, 2014/02/18
- Re: nested functions?, Vic Norton, 2014/02/18
- Re: nested functions?, fork, 2014/02/19
- Re: nested functions?, c., 2014/02/19
- Re: nested functions?, Vic Norton, 2014/02/20
- Re: nested functions?, c., 2014/02/20
- Unmaintained packages on Octave-Forge, Jordi GutiƩrrez Hermoso, 2014/02/20
- Re: Unmaintained packages on Octave-Forge, c., 2014/02/20