octave 3 vs 4 script compatibility; where's REAL documentation of Executable-Octave-Programs











up vote
1
down vote

favorite












Part-1: In octave 3.4.3 (on centos 6.6) following script file "joe.m" (but for 3.x minus --no-gui):



#!/bin/bash
# for-bash:
#{
exec octave -q --no-gui --no-init-file "$0" ${1+"$@"}
#}
# for-octave:
function jim ()
printf ("program_name: '%s'n", program_name ());
endfunction
printf ("calling jimn")
jim


produces output:



calling jim
program_name: 'joe.m'


But in octave 4.2.1 it gives a warning, and appears to auto-call(!?) jim, and does NOT run top-level immediate code(!?), no output line "calling jim":



warning: function name 'jim' does not agree with function filename '/tmp/joe.m'
program_name: 'joe.m'


Part-2: If I rename same file to "jim.m", then in octave 3.4.4 the output is:



calling jim
program_name: 'jim.m'


in octave 4.2.1 now warning is avoided, but still missing "calling jim" line.



Part-3: With zero functions defined, the top-level code will execute in both versions.



Where are these behaviors (and this change of behavior from version 3 to 4) documented or controlled? Nothing of the sort is mentioned in:



https://octave.org/doc/v4.2.1/Command-Line-Options.html



https://octave.org/doc/v4.2.1/Executable-Octave-Programs.html



How can one write an octave file compatible with both version 3.x and 4.x, or how to invoke 4.x with an extra option to behave compatibly with 3.x? How to execute top-level code in 4.x even when functions are defined?



How can one deterministically know (without trial and error) what function will be auto-called (and with what arguments) in 4.x without documentation of same? This example not enough to nail it down, since there's one and only one function: if there are multiple functions (joe and jim), does the order matter, relative to whether either or none matches the file name?



Edit: I include the shebang (self-contained script) in attempt to not "ask the wrong question" or prematurely optimize the question towards my own "attempted solution", yet behaviors are same with or without it. I need script to: not use absolute path to octave, and accept extra separate options (I could not combine --no-gui into -qf in 4.2.1). Your simplifications are welcome.










share|improve this question




















  • 1




    If the shebang line is not relevant to the question, please remove it. It took me a while to parse that. Let people focus on what is important. See Minimal, Complete, and Verifiable example (especially the minimal part!).
    – Cris Luengo
    Nov 19 at 14:15












  • Thanks. I made an edit to explain. Maybe I better split-out the shebang to an afterword.
    – bk-se
    Nov 20 at 20:54















up vote
1
down vote

favorite












Part-1: In octave 3.4.3 (on centos 6.6) following script file "joe.m" (but for 3.x minus --no-gui):



#!/bin/bash
# for-bash:
#{
exec octave -q --no-gui --no-init-file "$0" ${1+"$@"}
#}
# for-octave:
function jim ()
printf ("program_name: '%s'n", program_name ());
endfunction
printf ("calling jimn")
jim


produces output:



calling jim
program_name: 'joe.m'


But in octave 4.2.1 it gives a warning, and appears to auto-call(!?) jim, and does NOT run top-level immediate code(!?), no output line "calling jim":



warning: function name 'jim' does not agree with function filename '/tmp/joe.m'
program_name: 'joe.m'


Part-2: If I rename same file to "jim.m", then in octave 3.4.4 the output is:



calling jim
program_name: 'jim.m'


in octave 4.2.1 now warning is avoided, but still missing "calling jim" line.



Part-3: With zero functions defined, the top-level code will execute in both versions.



Where are these behaviors (and this change of behavior from version 3 to 4) documented or controlled? Nothing of the sort is mentioned in:



https://octave.org/doc/v4.2.1/Command-Line-Options.html



https://octave.org/doc/v4.2.1/Executable-Octave-Programs.html



How can one write an octave file compatible with both version 3.x and 4.x, or how to invoke 4.x with an extra option to behave compatibly with 3.x? How to execute top-level code in 4.x even when functions are defined?



How can one deterministically know (without trial and error) what function will be auto-called (and with what arguments) in 4.x without documentation of same? This example not enough to nail it down, since there's one and only one function: if there are multiple functions (joe and jim), does the order matter, relative to whether either or none matches the file name?



Edit: I include the shebang (self-contained script) in attempt to not "ask the wrong question" or prematurely optimize the question towards my own "attempted solution", yet behaviors are same with or without it. I need script to: not use absolute path to octave, and accept extra separate options (I could not combine --no-gui into -qf in 4.2.1). Your simplifications are welcome.










share|improve this question




















  • 1




    If the shebang line is not relevant to the question, please remove it. It took me a while to parse that. Let people focus on what is important. See Minimal, Complete, and Verifiable example (especially the minimal part!).
    – Cris Luengo
    Nov 19 at 14:15












  • Thanks. I made an edit to explain. Maybe I better split-out the shebang to an afterword.
    – bk-se
    Nov 20 at 20:54













up vote
1
down vote

favorite









up vote
1
down vote

favorite











Part-1: In octave 3.4.3 (on centos 6.6) following script file "joe.m" (but for 3.x minus --no-gui):



#!/bin/bash
# for-bash:
#{
exec octave -q --no-gui --no-init-file "$0" ${1+"$@"}
#}
# for-octave:
function jim ()
printf ("program_name: '%s'n", program_name ());
endfunction
printf ("calling jimn")
jim


produces output:



calling jim
program_name: 'joe.m'


But in octave 4.2.1 it gives a warning, and appears to auto-call(!?) jim, and does NOT run top-level immediate code(!?), no output line "calling jim":



warning: function name 'jim' does not agree with function filename '/tmp/joe.m'
program_name: 'joe.m'


Part-2: If I rename same file to "jim.m", then in octave 3.4.4 the output is:



calling jim
program_name: 'jim.m'


in octave 4.2.1 now warning is avoided, but still missing "calling jim" line.



Part-3: With zero functions defined, the top-level code will execute in both versions.



Where are these behaviors (and this change of behavior from version 3 to 4) documented or controlled? Nothing of the sort is mentioned in:



https://octave.org/doc/v4.2.1/Command-Line-Options.html



https://octave.org/doc/v4.2.1/Executable-Octave-Programs.html



How can one write an octave file compatible with both version 3.x and 4.x, or how to invoke 4.x with an extra option to behave compatibly with 3.x? How to execute top-level code in 4.x even when functions are defined?



How can one deterministically know (without trial and error) what function will be auto-called (and with what arguments) in 4.x without documentation of same? This example not enough to nail it down, since there's one and only one function: if there are multiple functions (joe and jim), does the order matter, relative to whether either or none matches the file name?



Edit: I include the shebang (self-contained script) in attempt to not "ask the wrong question" or prematurely optimize the question towards my own "attempted solution", yet behaviors are same with or without it. I need script to: not use absolute path to octave, and accept extra separate options (I could not combine --no-gui into -qf in 4.2.1). Your simplifications are welcome.










share|improve this question















Part-1: In octave 3.4.3 (on centos 6.6) following script file "joe.m" (but for 3.x minus --no-gui):



#!/bin/bash
# for-bash:
#{
exec octave -q --no-gui --no-init-file "$0" ${1+"$@"}
#}
# for-octave:
function jim ()
printf ("program_name: '%s'n", program_name ());
endfunction
printf ("calling jimn")
jim


produces output:



calling jim
program_name: 'joe.m'


But in octave 4.2.1 it gives a warning, and appears to auto-call(!?) jim, and does NOT run top-level immediate code(!?), no output line "calling jim":



warning: function name 'jim' does not agree with function filename '/tmp/joe.m'
program_name: 'joe.m'


Part-2: If I rename same file to "jim.m", then in octave 3.4.4 the output is:



calling jim
program_name: 'jim.m'


in octave 4.2.1 now warning is avoided, but still missing "calling jim" line.



Part-3: With zero functions defined, the top-level code will execute in both versions.



Where are these behaviors (and this change of behavior from version 3 to 4) documented or controlled? Nothing of the sort is mentioned in:



https://octave.org/doc/v4.2.1/Command-Line-Options.html



https://octave.org/doc/v4.2.1/Executable-Octave-Programs.html



How can one write an octave file compatible with both version 3.x and 4.x, or how to invoke 4.x with an extra option to behave compatibly with 3.x? How to execute top-level code in 4.x even when functions are defined?



How can one deterministically know (without trial and error) what function will be auto-called (and with what arguments) in 4.x without documentation of same? This example not enough to nail it down, since there's one and only one function: if there are multiple functions (joe and jim), does the order matter, relative to whether either or none matches the file name?



Edit: I include the shebang (self-contained script) in attempt to not "ask the wrong question" or prematurely optimize the question towards my own "attempted solution", yet behaviors are same with or without it. I need script to: not use absolute path to octave, and accept extra separate options (I could not combine --no-gui into -qf in 4.2.1). Your simplifications are welcome.







octave






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 20:49

























asked Nov 19 at 9:09









bk-se

17516




17516








  • 1




    If the shebang line is not relevant to the question, please remove it. It took me a while to parse that. Let people focus on what is important. See Minimal, Complete, and Verifiable example (especially the minimal part!).
    – Cris Luengo
    Nov 19 at 14:15












  • Thanks. I made an edit to explain. Maybe I better split-out the shebang to an afterword.
    – bk-se
    Nov 20 at 20:54














  • 1




    If the shebang line is not relevant to the question, please remove it. It took me a while to parse that. Let people focus on what is important. See Minimal, Complete, and Verifiable example (especially the minimal part!).
    – Cris Luengo
    Nov 19 at 14:15












  • Thanks. I made an edit to explain. Maybe I better split-out the shebang to an afterword.
    – bk-se
    Nov 20 at 20:54








1




1




If the shebang line is not relevant to the question, please remove it. It took me a while to parse that. Let people focus on what is important. See Minimal, Complete, and Verifiable example (especially the minimal part!).
– Cris Luengo
Nov 19 at 14:15






If the shebang line is not relevant to the question, please remove it. It took me a while to parse that. Let people focus on what is important. See Minimal, Complete, and Verifiable example (especially the minimal part!).
– Cris Luengo
Nov 19 at 14:15














Thanks. I made an edit to explain. Maybe I better split-out the shebang to an afterword.
– bk-se
Nov 20 at 20:54




Thanks. I made an edit to explain. Maybe I better split-out the shebang to an afterword.
– bk-se
Nov 20 at 20:54












1 Answer
1






active

oldest

votes

















up vote
4
down vote













There are different .m file types including (according to Octave 4.2.1):





  1. Function files:
    A file that contains definition of one or more functions. The name of a function file often matches the name of the first function defined in the file.


  2. Script files:
    A file that contain lines of code including definition of functions.




    Unlike a function file, a script file must not begin with the keyword function . If it does, Octave will assume that it is a function file, and that it defines a single function that should be evaluated as soon as it is defined.




  3. Class definition files.



The behavior of Octave when is executed as:



$octave File


is documented in one of source files (oct-parse.yy) of Octave:




Execute the contents of a script file. For compatibility with Matlab, also execute a function file by calling the function it defines with no arguments and nargout = 0.




Here because your file begins with the keyword function it is considered as a function file so the function jim is automatically called regardless of if you invoke jim or not. So you can remove the expression jim from the end of file and see that the function is automatically called. In version 3.4.3 I think it is assumed as a script file.



To solve the problem you need to add an expression,other than the function keyword, to the beginning of the file to convert it to a script file:



#!/bin/bash
# for-bash:
#{
exec octave -q --no-init-file "$0" ${1+"$@"}
#}
# for-octave:
1;
function jim ()
printf ("program_name: '%s'n", program_name ());
endfunction
printf ("calling jimn")
jim





share|improve this answer





















  • That's a big help. 3.x & 4.x compatibility still not addressed. And I get complimentary warnings (4.x seems a mine field of warnings), function-name vs file-name warns when they match (script file), and when they don't (function file).
    – bk-se
    Nov 20 at 21:04










  • If you want to disable warnings you can put the following command in the startup file : warning( 'off','Octave:function-name-clash'). You can find here list of all warnings. I think that behavior of 3.x is a bug and is fixed later. If you need 3.x you can install both 4.x and 3.x and use which of you want.
    – rahnema1
    Nov 20 at 21:45










  • Only way I've found to disable warning when script file has function of same name is warning( 'off','all'); and no way to do that in time if using -qf. Forces me to rename functions (or script files) from octave 3 to use them in octave 4.
    – bk-se
    Nov 21 at 1:20











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371367%2foctave-3-vs-4-script-compatibility-wheres-real-documentation-of-executable-oct%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote













There are different .m file types including (according to Octave 4.2.1):





  1. Function files:
    A file that contains definition of one or more functions. The name of a function file often matches the name of the first function defined in the file.


  2. Script files:
    A file that contain lines of code including definition of functions.




    Unlike a function file, a script file must not begin with the keyword function . If it does, Octave will assume that it is a function file, and that it defines a single function that should be evaluated as soon as it is defined.




  3. Class definition files.



The behavior of Octave when is executed as:



$octave File


is documented in one of source files (oct-parse.yy) of Octave:




Execute the contents of a script file. For compatibility with Matlab, also execute a function file by calling the function it defines with no arguments and nargout = 0.




Here because your file begins with the keyword function it is considered as a function file so the function jim is automatically called regardless of if you invoke jim or not. So you can remove the expression jim from the end of file and see that the function is automatically called. In version 3.4.3 I think it is assumed as a script file.



To solve the problem you need to add an expression,other than the function keyword, to the beginning of the file to convert it to a script file:



#!/bin/bash
# for-bash:
#{
exec octave -q --no-init-file "$0" ${1+"$@"}
#}
# for-octave:
1;
function jim ()
printf ("program_name: '%s'n", program_name ());
endfunction
printf ("calling jimn")
jim





share|improve this answer





















  • That's a big help. 3.x & 4.x compatibility still not addressed. And I get complimentary warnings (4.x seems a mine field of warnings), function-name vs file-name warns when they match (script file), and when they don't (function file).
    – bk-se
    Nov 20 at 21:04










  • If you want to disable warnings you can put the following command in the startup file : warning( 'off','Octave:function-name-clash'). You can find here list of all warnings. I think that behavior of 3.x is a bug and is fixed later. If you need 3.x you can install both 4.x and 3.x and use which of you want.
    – rahnema1
    Nov 20 at 21:45










  • Only way I've found to disable warning when script file has function of same name is warning( 'off','all'); and no way to do that in time if using -qf. Forces me to rename functions (or script files) from octave 3 to use them in octave 4.
    – bk-se
    Nov 21 at 1:20















up vote
4
down vote













There are different .m file types including (according to Octave 4.2.1):





  1. Function files:
    A file that contains definition of one or more functions. The name of a function file often matches the name of the first function defined in the file.


  2. Script files:
    A file that contain lines of code including definition of functions.




    Unlike a function file, a script file must not begin with the keyword function . If it does, Octave will assume that it is a function file, and that it defines a single function that should be evaluated as soon as it is defined.




  3. Class definition files.



The behavior of Octave when is executed as:



$octave File


is documented in one of source files (oct-parse.yy) of Octave:




Execute the contents of a script file. For compatibility with Matlab, also execute a function file by calling the function it defines with no arguments and nargout = 0.




Here because your file begins with the keyword function it is considered as a function file so the function jim is automatically called regardless of if you invoke jim or not. So you can remove the expression jim from the end of file and see that the function is automatically called. In version 3.4.3 I think it is assumed as a script file.



To solve the problem you need to add an expression,other than the function keyword, to the beginning of the file to convert it to a script file:



#!/bin/bash
# for-bash:
#{
exec octave -q --no-init-file "$0" ${1+"$@"}
#}
# for-octave:
1;
function jim ()
printf ("program_name: '%s'n", program_name ());
endfunction
printf ("calling jimn")
jim





share|improve this answer





















  • That's a big help. 3.x & 4.x compatibility still not addressed. And I get complimentary warnings (4.x seems a mine field of warnings), function-name vs file-name warns when they match (script file), and when they don't (function file).
    – bk-se
    Nov 20 at 21:04










  • If you want to disable warnings you can put the following command in the startup file : warning( 'off','Octave:function-name-clash'). You can find here list of all warnings. I think that behavior of 3.x is a bug and is fixed later. If you need 3.x you can install both 4.x and 3.x and use which of you want.
    – rahnema1
    Nov 20 at 21:45










  • Only way I've found to disable warning when script file has function of same name is warning( 'off','all'); and no way to do that in time if using -qf. Forces me to rename functions (or script files) from octave 3 to use them in octave 4.
    – bk-se
    Nov 21 at 1:20













up vote
4
down vote










up vote
4
down vote









There are different .m file types including (according to Octave 4.2.1):





  1. Function files:
    A file that contains definition of one or more functions. The name of a function file often matches the name of the first function defined in the file.


  2. Script files:
    A file that contain lines of code including definition of functions.




    Unlike a function file, a script file must not begin with the keyword function . If it does, Octave will assume that it is a function file, and that it defines a single function that should be evaluated as soon as it is defined.




  3. Class definition files.



The behavior of Octave when is executed as:



$octave File


is documented in one of source files (oct-parse.yy) of Octave:




Execute the contents of a script file. For compatibility with Matlab, also execute a function file by calling the function it defines with no arguments and nargout = 0.




Here because your file begins with the keyword function it is considered as a function file so the function jim is automatically called regardless of if you invoke jim or not. So you can remove the expression jim from the end of file and see that the function is automatically called. In version 3.4.3 I think it is assumed as a script file.



To solve the problem you need to add an expression,other than the function keyword, to the beginning of the file to convert it to a script file:



#!/bin/bash
# for-bash:
#{
exec octave -q --no-init-file "$0" ${1+"$@"}
#}
# for-octave:
1;
function jim ()
printf ("program_name: '%s'n", program_name ());
endfunction
printf ("calling jimn")
jim





share|improve this answer












There are different .m file types including (according to Octave 4.2.1):





  1. Function files:
    A file that contains definition of one or more functions. The name of a function file often matches the name of the first function defined in the file.


  2. Script files:
    A file that contain lines of code including definition of functions.




    Unlike a function file, a script file must not begin with the keyword function . If it does, Octave will assume that it is a function file, and that it defines a single function that should be evaluated as soon as it is defined.




  3. Class definition files.



The behavior of Octave when is executed as:



$octave File


is documented in one of source files (oct-parse.yy) of Octave:




Execute the contents of a script file. For compatibility with Matlab, also execute a function file by calling the function it defines with no arguments and nargout = 0.




Here because your file begins with the keyword function it is considered as a function file so the function jim is automatically called regardless of if you invoke jim or not. So you can remove the expression jim from the end of file and see that the function is automatically called. In version 3.4.3 I think it is assumed as a script file.



To solve the problem you need to add an expression,other than the function keyword, to the beginning of the file to convert it to a script file:



#!/bin/bash
# for-bash:
#{
exec octave -q --no-init-file "$0" ${1+"$@"}
#}
# for-octave:
1;
function jim ()
printf ("program_name: '%s'n", program_name ());
endfunction
printf ("calling jimn")
jim






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 12:43









rahnema1

9,7202922




9,7202922












  • That's a big help. 3.x & 4.x compatibility still not addressed. And I get complimentary warnings (4.x seems a mine field of warnings), function-name vs file-name warns when they match (script file), and when they don't (function file).
    – bk-se
    Nov 20 at 21:04










  • If you want to disable warnings you can put the following command in the startup file : warning( 'off','Octave:function-name-clash'). You can find here list of all warnings. I think that behavior of 3.x is a bug and is fixed later. If you need 3.x you can install both 4.x and 3.x and use which of you want.
    – rahnema1
    Nov 20 at 21:45










  • Only way I've found to disable warning when script file has function of same name is warning( 'off','all'); and no way to do that in time if using -qf. Forces me to rename functions (or script files) from octave 3 to use them in octave 4.
    – bk-se
    Nov 21 at 1:20


















  • That's a big help. 3.x & 4.x compatibility still not addressed. And I get complimentary warnings (4.x seems a mine field of warnings), function-name vs file-name warns when they match (script file), and when they don't (function file).
    – bk-se
    Nov 20 at 21:04










  • If you want to disable warnings you can put the following command in the startup file : warning( 'off','Octave:function-name-clash'). You can find here list of all warnings. I think that behavior of 3.x is a bug and is fixed later. If you need 3.x you can install both 4.x and 3.x and use which of you want.
    – rahnema1
    Nov 20 at 21:45










  • Only way I've found to disable warning when script file has function of same name is warning( 'off','all'); and no way to do that in time if using -qf. Forces me to rename functions (or script files) from octave 3 to use them in octave 4.
    – bk-se
    Nov 21 at 1:20
















That's a big help. 3.x & 4.x compatibility still not addressed. And I get complimentary warnings (4.x seems a mine field of warnings), function-name vs file-name warns when they match (script file), and when they don't (function file).
– bk-se
Nov 20 at 21:04




That's a big help. 3.x & 4.x compatibility still not addressed. And I get complimentary warnings (4.x seems a mine field of warnings), function-name vs file-name warns when they match (script file), and when they don't (function file).
– bk-se
Nov 20 at 21:04












If you want to disable warnings you can put the following command in the startup file : warning( 'off','Octave:function-name-clash'). You can find here list of all warnings. I think that behavior of 3.x is a bug and is fixed later. If you need 3.x you can install both 4.x and 3.x and use which of you want.
– rahnema1
Nov 20 at 21:45




If you want to disable warnings you can put the following command in the startup file : warning( 'off','Octave:function-name-clash'). You can find here list of all warnings. I think that behavior of 3.x is a bug and is fixed later. If you need 3.x you can install both 4.x and 3.x and use which of you want.
– rahnema1
Nov 20 at 21:45












Only way I've found to disable warning when script file has function of same name is warning( 'off','all'); and no way to do that in time if using -qf. Forces me to rename functions (or script files) from octave 3 to use them in octave 4.
– bk-se
Nov 21 at 1:20




Only way I've found to disable warning when script file has function of same name is warning( 'off','all'); and no way to do that in time if using -qf. Forces me to rename functions (or script files) from octave 3 to use them in octave 4.
– bk-se
Nov 21 at 1:20


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371367%2foctave-3-vs-4-script-compatibility-wheres-real-documentation-of-executable-oct%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen