bugGNU Octave - Bugs: bug #37520, run() does not execute functions

 
 

bug #37520: run() does not execute functions

Submitted by:  None
Submitted on:  Sun 07 Oct 2012 02:10:29 PM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: InvalidAssigned to: None
Originator Name: Clemens BuchacherOriginator Email: -unavailable-
Open/Closed: ClosedRelease: 3.6.1
Operating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Mon 08 Oct 2012 06:33:48 PM UTC, comment #4:

".... to be Matlab compatible in this case."

Nowhere in the ML docs I could find mention of "run <function.m>"

The Octave project does not strive for "compatibility" with undocumented Matlab functionality.

Philip Nienhuis <philipnienhuis>
Project Member
Mon 08 Oct 2012 02:34:10 PM UTC, comment #3:

Although the Matlab documentation says run() is there to document scripts, it does actually run functions just fine as well, and it does not interpret them as scripts or anything.

In fact, the function below works in Matlab and Octave, and it reproduces the correct behavior in this context. So, I do not think it would be hard or disadvantageous to be Matlab compatible in this case.

I can't really comment on the links that you are referring to, since they seem to deal with different issues.

Regards,
Clemens
---

function runit(s)

[p,s,ext]=fileparts(s);
cwd = pwd();
cd(p);
try
eval([s ';']);
catch e
cd(cwd)
rethrow(e);
end

cd(cwd);

Anonymous
Sun 07 Oct 2012 06:05:14 PM UTC, comment #2:

Run does not execute functions. It executes scripts. If you attempt to run a function as a script, all that happens is that the function file is executed as a script file, i.e. the function is parsed and loaded into the symbol table.

Since Matlab doesn't allow defining functions in script files, there is no need to attempt compatibility here.

Jordi GutiƩrrez Hermoso <jordigh>
Project Administrator
Sun 07 Oct 2012 04:55:12 PM UTC, comment #1:

run does work, but produces no output. See bug #37467 and see also here:
http://www.mathworks.com/matlabcentral/answers/45138

http://stackoverflow.com/questions/9205627/is-it-possible-to-call-a-function-that-is-not-in-the-path-in-matlab

Why would you invoke a function using "run"? I think that's not what functions are meant for in the first place.

As to "unpredictable effect of scripts on the caller's variables": scripts usually aren't intended to produce "unpredictable" results and/or effects, are they.

Philip Nienhuis <philipnienhuis>
Project Member
Sun 07 Oct 2012 02:10:29 PM UTC, original submission:

Tested on computer('arch'): mingw32-i686 and gnu-linux-x84_64.

$ cat <<EOF >mypath.m
function mypath()
fprintf('hi\n');
EOF
$ octave

> run('mypath.m')
>


Expected result: Writes "hi" to stdout. (Tested with Matlab R2011b)
Actual result: No output.

I think run'ing functions is a lot more useful than run'ing scripts due to the unpredictable effect of scripts on the caller's variables.

Forgot to check if Matlab allows passing arguments as well.

Anonymous

 

(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 jordigh (Posted a comment)
  • -unavailable- added by philipnienhuis (Posted a comment)
  • -unavailable- added by None (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 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 07 Oct 2012 06:05:14 PM UTCjordighStatusNone=>Invalid
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1