Cannot "run" a function file in dev branch.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Cannot "run" a function file in dev branch.

siko1056
Hi,

Today I built HG ID 9f31de57ad36 [1] (which seems not related to the issue, it must have been some change in the past week) but ever since I cannot run function files using the "run" or "source" functions. The problem is reproducible by creating a tiny echo function file:

$ echo -e "function doit() \n disp ('hi') \nendfunction" > doit.m

From within Octave's GUI execution works fine by pressing the "Run" button or "F5" and it works in GUI and CLI by typing:

>> doit

hi

But not when trying something like this:

>> run ("/workspace/doit.m")
>> run ("doit.m")
>> source ("doit.m")

Script files seem not to be affected. There were some changes to the interpreter, that I do not fully grasp that fast. Any ideas or is there something under construction for a while? That is why I did not file a bug report yet.

Thank you for you attention,

Kai

P.S.: Both functions are not part of Octave's BIST and do not occur that often in Octave's m-files. So regressions might happen unnoticed.

[1] https://hg.savannah.gnu.org/hgweb/octave/rev/9f31de57ad36
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cannot "run" a function file in dev branch.

Rik-4
On 08/08/2017 09:00 AM, [hidden email] wrote:
Subject:
Cannot "run" a function file in dev branch.
From:
siko1056 [hidden email]
Date:
08/07/2017 12:42 PM
To:
[hidden email]
List-Post:
[hidden email]
Content-Transfer-Encoding:
7bit
Precedence:
list
MIME-Version:
1.0
Message-ID:
[hidden email]
Content-Type:
text/plain; charset=us-ascii
Message:
2

Hi,

Today I built HG ID 9f31de57ad36 [1] (which seems not related to the issue,
it must have been some change in the past week) but ever since I cannot run
function files using the "run" or "source" functions. The problem is
reproducible by creating a tiny echo function file:

$ echo -e "function doit() \n disp ('hi') \nendfunction" > doit.m

>From within Octave's GUI execution works fine by pressing the "Run" button
or "F5" and it works in GUI and CLI by typing:

doit
hi

But not when trying something like this:

run ("/workspace/doit.m")
run ("doit.m")
source ("doit.m")
Script files seem not to be affected. There were some changes to the
interpreter, that I do not fully grasp that fast. Any ideas or is there
something under construction for a while? That is why I did not file a bug
report yet.

Thank you for you attention,

Kai

P.S.: Both functions are not part of Octave's BIST and do not occur that
often in Octave's m-files. So regressions might happen unnoticed.

[1] https://hg.savannah.gnu.org/hgweb/octave/rev/9f31de57ad36

The issue here is a misconception of what source and run do.  They execute script files, not invoke functions.  So in the example you gave all that Octave did was parse the file and add the function as a command-line function exactly as if you had typed the script at the Octave prompt.  From what I can tell, this is what Matlab does as well (https://www.mathworks.com/help/matlab/ref/run.html).  Just to be sure, someone could try your script in Matlab and see.

This is a change, however, from what Octave used to do in 4.2.1.  Maybe that should be documented in the NEWS file?

--Rik
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cannot "run" a function file in dev branch.

Mike Miller-4
On Tue, Aug 08, 2017 at 09:27:37 -0700, Rik wrote:
> The issue here is a misconception of what source and run do.  They execute
> script files, not invoke functions.  So in the example you gave all that
> Octave did was parse the file and add the function as a command-line
> function exactly as if you had typed the script at the Octave prompt.  From
> what I can tell, this is what Matlab does as well
> (https://www.mathworks.com/help/matlab/ref/run.html).  Just to be sure,
> someone could try your script in Matlab and see.

I don't have Matlab, and I can't find a reference at the moment, but I
think this was an intention change in the 4.2 release, probably for
compatibility.

Take a look at the discussion in https://savannah.gnu.org/bugs/?33411,
in particular comments #2 and #8.

This intentional change was subsequently lost in
https://hg.savannah.gnu.org/hgweb/octave/rev/3bb0a937c071, where the
source_file function no longer looks for functions from what I can tell.

--
mike

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cannot "run" a function file in dev branch.

siko1056
Mike Miller-4 wrote
On Tue, Aug 08, 2017 at 09:27:37 -0700, Rik wrote:
> The issue here is a misconception of what source and run do.  They execute
> script files, not invoke functions.  So in the example you gave all that
> Octave did was parse the file and add the function as a command-line
> function exactly as if you had typed the script at the Octave prompt.  From
> what I can tell, this is what Matlab does as well
> (https://www.mathworks.com/help/matlab/ref/run.html).  Just to be sure,
> someone could try your script in Matlab and see.

I don't have Matlab, and I can't find a reference at the moment, but I
think this was an intention change in the 4.2 release, probably for
compatibility.

Take a look at the discussion in https://savannah.gnu.org/bugs/?33411,
in particular comments #2 and #8.

This intentional change was subsequently lost in
https://hg.savannah.gnu.org/hgweb/octave/rev/3bb0a937c071, where the
source_file function no longer looks for functions from what I can tell.

--
mike
Rik and Mike you are right. The ´run´ command is documented for script files only, even for Matlab [1,2]. Since I worked with both I (miss)used it for calling setup scripts and functions (which are initially not on the load path), the latter without arguments. It was convenient and still works in Matlab R2017a (even though [2] says the opposite) and I noticed it by running my own test suite yesterday that "nothing" happened anymore. I don't think it's worth to be compatible to an undocumented Matlab (bug/feature?). To get around this I use from now on:

>> old_dir = cd ('/workspace'); doit (); cd (old_dir);

instead of `run ("/workspace/doit.m");`.

Thank you for your help,

Kai

[1]: https://www.gnu.org/software/octave/doc/interpreter/XREFrun
[2]: https://www.mathworks.com/help/matlab/ref/run.html
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cannot "run" a function file in dev branch.

Mike Miller-4
On Tue, Aug 08, 2017 at 11:00:10 -0700, siko1056 wrote:
> Rik and Mike you are right. The ´run´ command is documented for script files
> only, even for Matlab [1,2]. Since I worked with both I (miss)used it for
> calling setup scripts and functions (which are initially not on the load
> path), the latter without arguments. It was convenient and still works in
> Matlab R2017a (even though [2] says the opposite) and I noticed it by
> running my own test suite yesterday that "nothing" happened anymore. I don't
> think it's worth to be compatible to an undocumented Matlab (bug/feature?).

Sorry if I wasn't clear, I do think it's worthwhile restoring this
behavior even though it's undocumented.

There are a couple of advantages, it lets users call a function that may
not be on the load path, and it allows the Run button in the GUI editor
to be used on function files (as long as the function works when called
with no arguments).

--
mike

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cannot "run" a function file in dev branch.

John W. Eaton
Administrator
On 08/08/2017 02:17 PM, Mike Miller wrote:

> On Tue, Aug 08, 2017 at 11:00:10 -0700, siko1056 wrote:
>> Rik and Mike you are right. The ´run´ command is documented for script files
>> only, even for Matlab [1,2]. Since I worked with both I (miss)used it for
>> calling setup scripts and functions (which are initially not on the load
>> path), the latter without arguments. It was convenient and still works in
>> Matlab R2017a (even though [2] says the opposite) and I noticed it by
>> running my own test suite yesterday that "nothing" happened anymore. I don't
>> think it's worth to be compatible to an undocumented Matlab (bug/feature?).
>
> Sorry if I wasn't clear, I do think it's worthwhile restoring this
> behavior even though it's undocumented.

I pushed a fix here:

http://hg.savannah.gnu.org/hgweb/octave/rev/3cace95ce563

When I made the earlier change, I forgot about the compatibility issue
and was thinking that it only made sense to source scripts.  I didn't
notice any comments about it (so I added some in this changeset) and no
tests failed after my changes (it would be nice to have some; would
someone like to add a few?).

jwe


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cannot "run" a function file in dev branch.

siko1056
John W. Eaton wrote
Thank you for the patch jwe!

John W. Eaton wrote
[...] no  tests failed after my changes (it would be nice to have some; would someone like to add a few?).
I pushed a BIST for script and function file execution for `run`:

https://hg.savannah.gnu.org/hgweb/octave/rev/0d5fc6e4a96c

If you agree, I add a slightly modified version to `source`.

Kai.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cannot "run" a function file in dev branch.

John W. Eaton
Administrator
On 08/09/2017 05:27 AM, siko1056 wrote:

> I pushed a BIST for script and function file execution for `run`:
>
> https://hg.savannah.gnu.org/hgweb/octave/rev/0d5fc6e4a96c

Thanks.

> If you agree, I add a slightly modified version to `source`.

Yes, if they don't simply test the same thing that run is testing, then
go ahead and add tests for source as well.

jwe


Loading...