Comments on: PARSE: what is default value for SET?
For A84... I'd like to be sure we define the default value for SET of variables.
Currently the rule is: a variable will be SET only if its rule is successful. Otherwise, its value remains unmodified.
Example:
n: "y"
parse "a" [set n "x"]
?? n
"y"
The advantage is that you can setup the default easily.
The alternative is:
n: "y"
parse "a" [set n "x"]
?? n
none
I expect some of you have strong opinions one way or the other?
A possible solution is to provide a way to preset the variable within the parse rule (without a paren expression.)
BTW, this applies to COPY as well.
5 Comments Comments:
Ken Collins 28-Sep-2009 15:35:36 |
I prefer that SET modify a variable only if its rule succeeds. I have code where I set default values before using parse. | Brian Hawley 28-Sep-2009 19:26:23 |
As an alternative, perhaps set and copy could have an optional modifier called default that would allow you to specify the value that the variable would be set to if the rule fails, before the failure propagates, like this:set x default 0 integer!
By putting the default after the var but before the matching rule, you won't be affected by however variable-length the rule is, nor will you have to carry the failure state forward. The argument for the default option would be a literal or expression-in-a-paren, the same as with quote or the value argument of insert or change. | Ladislav 29-Sep-2009 7:44:41 |
I agree with Ken, the approach is the most flexible one and compatible with current coding practices. | Maxim Olivier-Adlhoch 30-Sep-2009 13:47:15 |
I also agree, especially since we can set none as the default, if that is what we want. | Carl Sassenrath 5-Oct-2009 14:50:26 |
Ok, behavior will remain as is. |
Post a Comment:
You can post a comment here. Keep it on-topic.
|