a puzzle...

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

a puzzle...

Muhali
ok, here is a real puzzle.

Put into a new directory these 4 files:

-----------------
# foo.m
global gfun
gfun = @fC ;
y = fA(e)
-----------------
# fA.m
function y = fA (x, f)
   global gfun
   if nargin < 2
      y = fA(x, gfun) ;
   else
      w = feval(f, x) ;
      y = feval("fB", w) ;     #  <---  this is crucial
   endif
endfunction
-----------------
# fB.m
function y = fB (x) y = x ; endfunction
-----------------
# fC.m
function y = fC (x) y = x ; endfunction
-----------------

From that direcotry, assuming '.' is in the path, you get:

%> octave -q foo.m
y =  2.7183

Nice. But when in fA.m '"fB"' is replaced by '@fB' one gets

%> octave -q foo.m
error: `w' undefined near line 7 column 22
error: evaluating argument list element number 2
error: called from:
error:   /home/muhali/fA.m at line 7, column 9
error:   /home/muhali/fA.m at line 4, column 9
error:   /home/muhali/foo.m at line 3, column 3

Why is that?

M.
Reply | Threaded
Open this post in threaded view
|

Re: a puzzle...

bpabbott
Administrator

On Feb 4, 2012, at 4:07 AM, Muhali wrote:

> ok, here is a real puzzle.
>
> Put into a new directory these 4 files:
>
> -----------------
> # foo.m
> global gfun
> gfun = @fC ;
> y = fA(e)
> -----------------
> # fA.m
> function y = fA (x, f)
>   global gfun
>   if nargin < 2
>      y = fA(x, gfun) ;
>   else
>      w = feval(f, x) ;
>      y = feval("fB", w) ;     #  <---  this is crucial
>   endif
> endfunction
> -----------------
> # fB.m
> function y = fB (x) y = x ; endfunction
> -----------------
> # fC.m
> function y = fC (x) y = x ; endfunction
> -----------------
>
> From that direcotry, assuming '.' is in the path, you get:
>
> %> octave -q foo.m
> y =  2.7183
>
> Nice. But when in fA.m '"fB"' is replaced by '@fB' one gets
>
> %> octave -q foo.m
> error: `w' undefined near line 7 column 22
> error: evaluating argument list element number 2
> error: called from:
> error:   /home/muhali/fA.m at line 7, column 9
> error:   /home/muhali/fA.m at line 4, column 9
> error:   /home/muhali/foo.m at line 3, column 3
>
> Why is that?
>
> M.

I ran your example from Octave's command line.  With ..,

        y = feval ("fB", w);

... and with ...

        y = feval (@fB, w);

... I obtained the same result.

        y =  2.7183

I'm running a recent tip.

Did you include the single-quotes, like below ?

        y = feval ('@fB', w);

What version of Octave are you running ? Do you get the same result from Octave's command line as when you run from your shell's prompt.

Ben



_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: a puzzle...

Muhali
> Did you include the single-quotes, like below ?
>
> y = feval ('@fB', w);

I used no quotes.

> What version of Octave are you running ? Do you get the same result from Octave's command line as when you run from your shell's prompt.

Same result interactively or from the shell. It was done using

846273dae16b (stable)

Are you sure that when you ran the handle version (@) the function fB was not somehow referenced before?

M.
Reply | Threaded
Open this post in threaded view
|

Re: a puzzle...

bpabbott
Administrator

On Feb 4, 2012, at 1:12 PM, Muhali wrote:

>> Did you include the single-quotes, like below ?
>>
>> y = feval ('@fB', w);
>
> I used no quotes.
>
>> What version of Octave are you running ? Do you get the same result from
>> Octave's command line as when you run from your shell's prompt.
>
> Same result interactively or from the shell. It was done using
>
> 846273dae16b (stable)
>
> Are you sure that when you ran the handle version (@) the function fB was
> not somehow referenced before?
>
> M.
ahh ... I had placed all the functions into one script. That works. When I place each function in separate file and make a slight mod to fA.m ...

function y = fA (x, f)
  global gfun
  if nargin < 2
    disp ("nargin < 2")
    y = fA(x, gfun);
  else
    disp ("nargin >= 2")
    w = feval (f, x)
    y = feval (@fB, w);
  endif
endfunction

Then running foo.m gives ...

foo
w =  2.7183
error: `w' undefined near line 9 column 21
error: evaluating argument list element number 2
error: called from:
error:   /Users/bpabbott/Development/Octave_Toolbox/misc/Muhali/fA.m at line 9, column 7
error:   /Users/bpabbott/Development/Octave_Toolbox/misc/Muhali/fA.m at line 5, column 7
error:   /Users/bpabbott/Development/Octave_Toolbox/misc/Muhali/foo.m at line 4, column 3

This looks like a bug to me. I've made some minor changes to  your example and zipped them up. Running the modified foo.m, I get ....

 foo
w =  2.7183
y =  2.7183
w =  2.7183
error: `w' undefined near line 7 column 21
error: evaluating argument list element number 2
error: called from:
error:   /Users/bpabbott/Development/Octave_Toolbox/misc/Muhali/fA.m at line 7, column 7
error:   /Users/bpabbott/Development/Octave_Toolbox/misc/Muhali/fA.m at line 4, column 7
error:   /Users/bpabbott/Development/Octave_Toolbox/misc/Muhali/foo.m at line 8, column 3

I'll file a bug report.

Ben


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave

Archive.zip (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: a puzzle...

martin_helm
In reply to this post by Muhali
Am Samstag, 4. Februar 2012, 19:12:04 schrieb Muhali:

> > Did you include the single-quotes, like below ?
> >
> > y = feval ('@fB', w);
>
> I used no quotes.
>
> > What version of Octave are you running ? Do you get the same result from
> > Octave's command line as when you run from your shell's prompt.
>
> Same result interactively or from the shell. It was done using
>
> 846273dae16b (stable)
>
> Are you sure that when you ran the handle version (@) the function fB was
> not somehow referenced before?
>
> M.
I see the exact same error as you do when using

      y = feval(@fB, w);

in fA.m with octave 3.4.3, 3.6.0 and also hg version branch default updated
and compiled an hour ago.

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: a puzzle...

bpabbott
Administrator
In reply to this post by bpabbott
On Feb 4, 2012, at 2:04 PM, Ben Abbott wrote:

> On Feb 4, 2012, at 1:12 PM, Muhali wrote:
>
>>> Did you include the single-quotes, like below ?
>>>
>>> y = feval ('@fB', w);
>>
>> I used no quotes.
>>
>>> What version of Octave are you running ? Do you get the same result from
>>> Octave's command line as when you run from your shell's prompt.
>>
>> Same result interactively or from the shell. It was done using
>>
>> 846273dae16b (stable)
>>
>> Are you sure that when you ran the handle version (@) the function fB was
>> not somehow referenced before?
>>
>> M.
>
> ahh ... I had placed all the functions into one script. That works. When I place each function in separate file and make a slight mod to fA.m ...
>
> function y = fA (x, f)
>  global gfun
>  if nargin < 2
>    disp ("nargin < 2")
>    y = fA(x, gfun);
>  else
>    disp ("nargin >= 2")
>    w = feval (f, x)
>    y = feval (@fB, w);
>  endif
> endfunction
>
> Then running foo.m gives ...
>
> foo
> w =  2.7183
> error: `w' undefined near line 9 column 21
> error: evaluating argument list element number 2
> error: called from:
> error:   /Users/bpabbott/Development/Octave_Toolbox/misc/Muhali/fA.m at line 9, column 7
> error:   /Users/bpabbott/Development/Octave_Toolbox/misc/Muhali/fA.m at line 5, column 7
> error:   /Users/bpabbott/Development/Octave_Toolbox/misc/Muhali/foo.m at line 4, column 3
>
> This looks like a bug to me. I've made some minor changes to  your example and zipped them up. Running the modified foo.m, I get ....
>
> foo
> w =  2.7183
> y =  2.7183
> w =  2.7183
> error: `w' undefined near line 7 column 21
> error: evaluating argument list element number 2
> error: called from:
> error:   /Users/bpabbott/Development/Octave_Toolbox/misc/Muhali/fA.m at line 7, column 7
> error:   /Users/bpabbott/Development/Octave_Toolbox/misc/Muhali/fA.m at line 4, column 7
> error:   /Users/bpabbott/Development/Octave_Toolbox/misc/Muhali/foo.m at line 8, column 3
>
> I'll file a bug report.
>
> Ben

I've filed a report.

        https://savannah.gnu.org/bugs/index.php

Ben


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: a puzzle...

Muhali
> I've filed a report.

Thanks Ben.

I assume your form of the bug is equivalent to the original version, which included the string version of the function and was slightly different. It is at least interesting that the example works for that and not for the handle version, isn't it?

M.
Reply | Threaded
Open this post in threaded view
|

Re: a puzzle...

bpabbott
Administrator
On Feb 4, 2012, at 3:33 PM, Muhali wrote:

>> I've filed a report.
>
> Thanks Ben.
>
> I assume your form of the bug is equivalent to the original version, which
> included the string version of the function and was slightly different. It
> is at least interesting that the example works for that and not for the
> handle version, isn't it?
>
> M.

I added a comment.

Thanks
Ben


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: a puzzle...

Muhali
thanks. But it should be "fB" not "FB".
Reply | Threaded
Open this post in threaded view
|

Re: a puzzle...

bpabbott
Administrator
On Feb 4, 2012, at 3:59 PM, Muhali wrote:

> thanks. But it should be "fB" not "FB".
>

jwe has pushed a changeset.

        http://hg.savannah.gnu.org/hgweb/octave/rev/8d1ae996c122

Ben


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: a puzzle...

martin_helm
Am 05.02.2012 20:40, schrieb Ben Abbott

> jwe has pushed a changeset
>
> http://hg.savannah.gnu.org/hgweb/octave/rev/8d1ae996c122
>
> Ben
Does anyone else now get a compile error that parse-private.h cannot be
found?

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: a puzzle...

martin_helm
In reply to this post by Muhali
Am Sonntag, 5. Februar 2012, 21:46:58 schrieb Ben Abbott:

> On Feb 5, 2012, at 3:07 PM, Martin Helm wrote:
> > Am 05.02.2012 20:40, schrieb Ben Abbott
> >
> >> jwe has pushed a changeset
> >>
> >> http://hg.savannah.gnu.org/hgweb/octave/rev/8d1ae996c122
> >>
> >> Ben
> >
> > Does anyone else now get a compile error*that parse-private.h cannot be
> > found? *
>
> jwe just pushed the missing file.
>
> Ben

Thank you for the info and sorry for the PM I clicked by accident reply not
reply to all.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave