DEFAULT exists to run a block of code to give something a value if it doesn't have one already.
>> x: ~
>> x: default [10 + 20]
>> print x
30
>> x: <some-tag>
>> x: default [10 + 20]
>> print x
<some-tag>
@gchiu at one time asked for an "anti-default". Rather than make the decision of whether to overwrite or not based on the content of the variable and only sometimes evaluate the block...always evaluate the block, then decide whether to overwrite or not based on the result of that evaluation.
The name suggested for it was UPDATE:
>> x: <some-tag>
>> x: update if false [<unused-tag>]
>> print x
<some-tag>
>> x: <some-tag>
>> x: update if true [10 + 20]
>> print x
30
This seems very useful to me. While simple conditionals can move assignments into the block of code, e.g. x: if c [v]
=> if c [x: v]
, more complex instances might have several points they'd have to selectively do the same assignment:
number-of-variants: update case [
whatever1 [do some stuff, 1020] ; update for this case
whatever2 [do some stuff, void] ; don't update in this case
whatever3 [do some stuff, 304] ; update for this case
] ; don't update if no matches
But what we noticed was that UPDATE has been taken for a somewhat esoteric port action that I don't think anyone is using at the moment.
REBOL: Update - Function Summary
I'm not totally getting it, as it seems sort of like a WAIT statement, a SYNC, a FLUSH, a FETCH... I dunno. UPDATE seems a strange word to grab when there's this nice other function for it.
It's in use... but the only mentions are internal. It's what native port actors use to "respond to WAKE-UP". The name could be bumped to ON-WAKE-UP.