bugGNU Octave - Bugs: bug #59405, Feature request: new arguments...

 
 

bug #59405: Feature request: new arguments block syntax for argument validation

Submitter:  Michael <scivision>
Submitted:  Tue 03 Nov 2020 02:51:17 PM UTC
   
 
Category:  Interpreter Severity:  1 - Wish
Priority:  3 - Low Item Group:  Feature Request
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 10 Jun 2021 06:14:18 PM UTC, comment #9: 

Michael: These changes won't appear in an Octave release until version 7.  After the initial release in a release series, changes are usually limited to bug fixes, not new features.

John W. Eaton <jwe>
Group administrator
Tue 08 Jun 2021 02:51:48 AM UTC, comment #8: 

Thanks I'll look forward to testing in a future release. It seems this was implemented just before the merge for 6.2.90 as these changes don't seem to be enabled in that version.
Thanks for implementing "arguments" even as a noop--this will possibly allow me to support Octave with my Matlab packages again.

Michael <scivision>
Wed 02 Jun 2021 07:54:27 PM UTC, comment #7: 

I could also use some feedback on this topic that is related to the new arguments blocks:

https://octave.discourse.group/t/deprecate-assignment-as-an-expression/1148

John W. Eaton <jwe>
Group administrator
Wed 02 Jun 2021 07:51:04 PM UTC, comment #6: 

I pushed the following changeset to allow Octave to parse arguments blocks

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

Note that this change only implements parsing so the syntax is accept but not evaluation.  Code that relies on arguments blocks to provide default values, perform type conversion or do anything else that is useful will likely produce incorrect results after this change.

Please see the commit message for more details.

John W. Eaton <jwe>
Group administrator
Sat 07 Nov 2020 11:59:52 PM UTC, comment #5: 

Thank you Andrew--my original thought to ignore the "arguments" block is therefore incorrect, as I neglected to consider the coercion possible within the arguments block.

Michael <scivision>
Sat 07 Nov 2020 12:20:23 PM UTC, comment #4: 


> Interestingly, I just checked
>  iskeyword ('arguments')
> and it returns false on Matlab.


Surprisingly, this is expected. "Contextual" keywords - keywords that only act as keywords within certain other blocks - are not considered to be keywords by "iskeyword()". So "properties", "events", "methods", "enumeration", and "arguments" all return false from iskeyword() in Matlab.

I don't think I would recommend partially implementing this by just ignoring argument blocks. (At least not by default? Maybe have an opt-in preference for that behavior?) The arguments block not only checks, but can coerce or convert the type and size of the input arguments, affecting the function's behavior and semantics and not just doing the equivalent of assert() checks. So porting over Matlab code and having it run but ignore arguments blocks could result in surprising errors, including silently producing incorrect/unexpected results and not just raising exceptions. (Though that's not super likely IMHO.)

Andrew Janke <apjanke>
Thu 05 Nov 2020 04:04:05 PM UTC, comment #3: 

Interestingly, I just checked


iskeyword ('arguments')


and it returns false on Matlab.  According to the documentation,


Functions define argument validation in code blocks that are delimited by the keywords arguments and end. If used, an arguments block must start before the first executable line of the function.


Thus, in terms of implementation, I think it will need to go with the parser when it detects a function prototype.  Octave would then need to search for one or more optional arguments/endarguments blocks, and when the first line of executable code is found drop back to normal interpretation.

Rik <rik5>
Group administrator
Tue 03 Nov 2020 06:44:21 PM UTC, comment #2: 

Thank you Yes I agree with the new "bug" metadata as a long term enhancement topic.
thanks for your comments.

Michael <scivision>
Tue 03 Nov 2020 04:51:02 PM UTC, comment #1: 

Confirmed.  This is new functionality for Matlab that has not been added to Octave.  I've change the release to the development branch because this will be a bit of a project to implement and won't be ready for a 6.1 release.

Rik <rik5>
Group administrator
Tue 03 Nov 2020 02:51:17 PM UTC, original submission:  

Matlab R2019b added function argument validation syntax: https://www.mathworks.com/help/matlab/matlab_prog/function-argument-validation-1.html
The current Octave interpreter (at least through Octave 6.0.92) sees this syntax as invalid.

Example



function y = timestwo(x)
arguments
  x {mustBeNumeric}
end

y = 2*x;

end


Possible workaround


If the Octave interpreter could at least be made to ignore the "arguments" block, this would allow more Matlab scripts to be run.

Michael <scivision>

 

(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 tutissanalio
  • -email is unavailable- added by apjanke (Posted a comment)
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by scivision (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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-12-27 tutissanalio Carbon-Copy- Added tutissanalio
    2020-11-03 jwe SummaryENH: R2019b argument validation syntax Feature request: new arguments block syntax for argument validation
    2020-11-03 jwe Severity3 - Normal 1 - Wish
        Priority5 - Normal 3 - Low
        Item GroupMatlab Compatibility Feature Request
    2020-11-03 rik5 StatusNone Confirmed
        Release6.0.92 dev

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code