bugGNU Octave - Bugs: bug #31484, anonymous functions don't see...

 
 

bug #31484: anonymous functions don't see functions in private/

Submitted by:  Olaf Till <i7tiol>
Submitted on:  Thu 28 Oct 2010 07:19:03 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 2Item Group: Other
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: devOperating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Wed 17 Nov 2010 07:40:50 PM UTC, comment #5:

I checked in the following changeset:

http://hg.savannah.gnu.org/hgweb/octave/rev/c78247b664fc

This appears to fix the problem for, so I'm closing this report.

John W. Eaton <jwe>
Project Administrator
Mon 01 Nov 2010 04:23:08 PM UTC, comment #4:

JWE beat me to it, but this bug is being re-opened since you can confirm the behavior on at least one version of Matlab.

There are at least two simple workarounds for users who discover this thread before this issue is fixed.

1) Call functions in private subdirectories directly, rather than through an anonymous function handle.

2) Use functions defined within the same '.m' file. Those functions after the first are file scoped, i.e., not visible in the global namespace and behave similarly to placing them in a './private/' directory.

Amended example:

Rik <rik5>
Project Administrator
Mon 01 Nov 2010 08:20:27 AM UTC, comment #3:

Rik has closed the bug due to Pascals comment.

Pascals comment says the the code is not valid for Matlab. This is probably not true.

1. I don't understand what caused the error-message seen by Pascal with Matlab 2009a. Anyway, the error-message was seen by running in Matlab the workaround for the bug, not the code that triggered the bug in Octave.

2. I have tested that the code triggering the bug in Octave is valid input for Matlab 2009b with the following:

in the current directory, there is the file "private_test.m":

function private_test ()
f = @ () test_private ();
f ();

and in the subdirectory "private" of the current directory there is the file "test_private.m":

function test_private ()
1;

Running

>> private_test ();


from Matlabs command prompt gives no error-messages (and returns to the command prompt without output, as expected). (In Octave, this procedure had triggered the bug.)

BTW even the originally posted workaround works with Matlab-2009b without error messages for me, provided that the variable name for the anonymous function is changed since Matlab does not seem to allow using a name for this which previously named a function (Pascal had done this, I can not see where his error-message came from).

The bug seems to show that Octaves anonymous functions do not preserve enough context to see functions in private directories. This might be important to note, even if the bug should not be fixed immediately.

Olaf Till <i7tiol>
Project Member
Sun 31 Oct 2010 04:52:40 PM UTC, comment #2:

Per Pascal's comment, the code is not valid input for Matlab.

In this case, I don't think adding the additional functionality beyond Matlab is worth the coding pain.

Rik <rik5>
Project Administrator
Fri 29 Oct 2010 08:03:32 AM UTC, comment #1:

I tested your program against Matlab 2009a
------ function private_test.m -------------
function private_test (x)

test_private_handle = @ test_private;

f = @ (x) test_private_handle(x);

f (3);

end
---------------------------------------------

>> test_private

??? Error: File: test_private.m Line: 1 Column: 29
"@" dotted names can be used only within a CLASS block.

Error in ==> test_private>@(x)test_private_handle(x) at 5
f = @ (x) test_private_handle(x);

Error in ==> test_private at 7
f (3);

So, it seems that having some func under a private dir can only be used in a "class" context.

Regards

Pascal

Pascal Dupuis <cdemills>
Project Member
Thu 28 Oct 2010 07:19:03 AM UTC, original submission:

In the following example, function 'private_test' is in the current directory, and function 'test_private' is an arbitrary function in the subdirectory private/ of the current directory.

function private_test ()

f = @ () test_private ();

f ();

endfunction

octave:1> private_test ()
error: `test_private' undefined near line 3 column 12
error: called from:
error: at line -1, column -1
error: /home/olaf/tp/tp/inst/private_test.m at line 5, column 3
octave:1>

One can workaround by setting a handle to test_private:

function private_test ()

test_private = @ test_private;

f = @ () test_private ();

f ();

endfunction

octave:1> private_test ()
octave:2>

Olaf Till <i7tiol>
Project Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jwe (Updated the item)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by cdemills (Posted a comment)
  • -unavailable- added by i7tiol (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 7 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 17 Nov 2010 07:40:50 PM UTCjweStatusConfirmed=>Fixed
      Open/ClosedOpen=>Closed
    Mon 01 Nov 2010 04:23:08 PM UTCrik5Priority5 - Normal=>2
    Mon 01 Nov 2010 03:44:21 PM UTCjweStatusWont Fix=>Confirmed
      Open/ClosedClosed=>Open
    Sun 31 Oct 2010 04:52:40 PM UTCrik5StatusNone=>Wont Fix
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1