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

 
 

bug #37520: run() does not execute functions

Submitter:  None
Submitted:  Sun 07 Oct 2012 02:10:29 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Clemens Buchacher Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.6.1
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

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>
Group 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>
Group Member
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>
Group 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 Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jordigh (Posted a comment)
  • -email is unavailable- added by philipnienhuis (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-10-07 jordigh StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code