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

 
 

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

Submitted by:  Michael <scivision>
Submitted on:  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

Add a New Comment (Rich Markup)
   

You are not logged in

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

 

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>
Project 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>
Project 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 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)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    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.5