[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #49793] octave's inputParser only accepts vali
From: |
anonymous |
Subject: |
[Octave-bug-tracker] [bug #49793] octave's inputParser only accepts validation functions that return true or false |
Date: |
Thu, 8 Dec 2016 09:45:49 +0000 (UTC) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0 |
Follow-up Comment #3, bug #49793 (project octave):
As in octave a || b apparently returns the logical value of b if a is
undefined (e.g. a is a call to a function which returns nothing), I suggest
the following one-line-fix in inputParser.m:
function validate_arg (this, name, val, in)
if (! val (in) || false ) % <- only this line changed!
this.error (sprintf ("failed validation of %s", toupper (name)));
endif
this.Results.(name) = in;
endfunction
The only drawback I see so far is, that 'failed validation of %s' is only
printed if the validation function does not throw an error before. Here a
hopefully comprehensive example, using inputParser.m patched as described
above:
octave:1> htest = @(h) validateattributes(h, {'double'}, {'nonnegative'});
octave:2>
octave:2> ip = inputParser;
octave:3> ip.addRequired('h', htest);
octave:4> ip.parse(1.0);
octave:5> ip.parse(-1.0);
error: input must be nonnegative
error: called from
validateattributes at line 406 column 7
validate_arg at line 505 column 9
parse at line 394 column 9
octave:5>
octave:5> function ret = myvalidatenonnegative(a)
> if a >= 0
> ret = true;
> else
> ret = false;
> endif
> endfunction
octave:6>
octave:6> Htest = @(h) myvalidatenonnegative(h)
Htest =
@(h) myvalidatenonnegative (h)
octave:7>
octave:7> ip = inputParser;
octave:8> ip.addRequired('h', Htest);
octave:9> ip.parse(1.0);
octave:10> ip.parse(-1.0);
error: failed validation of H
error: called from
error at line 539 column 7
validate_arg at line 506 column 11
parse at line 394 column 9
octave:10>
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?49793>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #49793] octave's inputParser only accepts validation functions that return true or false, anonymous, 2016/12/07
- [Octave-bug-tracker] [bug #49793] octave's inputParser only accepts validation functions that return true or false, Amro, 2016/12/07
- [Octave-bug-tracker] [bug #49793] octave's inputParser only accepts validation functions that return true or false, Amro, 2016/12/07
- [Octave-bug-tracker] [bug #49793] octave's inputParser only accepts validation functions that return true or false,
anonymous <=
- [Octave-bug-tracker] [bug #49793] octave's inputParser only accepts validation functions that return true or false, Amro, 2016/12/08
- [Octave-bug-tracker] [bug #49793] octave's inputParser only accepts validation functions that return true or false, John W. Eaton, 2016/12/08
- [Octave-bug-tracker] [bug #49793] octave's inputParser only accepts validation functions that return true or false, John W. Eaton, 2016/12/08
- [Octave-bug-tracker] [bug #49793] octave's inputParser only accepts validation functions that return true or false, Amro, 2016/12/08
- [Octave-bug-tracker] [bug #49793] octave's inputParser only accepts validation functions that return true or false, Mike Miller, 2016/12/17
- [Octave-bug-tracker] [bug #49793] octave's inputParser only accepts validation functions that return true or false, Amro, 2016/12/08