|
Introduction
The meanings of using
and save
are made a bit more complex by this example. The example illustrates some atypical aspects of shelf usage, which typically do not occur in a well-organized program.
The question is, when an "A" is found in the input, what is the value of counter "c" written to #process-output
? Is it 7, 25, or 26? The answer is 25.
The answer is based on the following rule: a shelf or attribute bound by a using
prefix, or by a modifiable or read-only function argument, refers to the"version" of the shelf or attribute that existed at the point that the using
prefix was performed or the function was called. This occurs independently of what may have happened within the action following the using
prefix or the local scope body of the called function.
In this example, within the using
prefix, "c" refers to the shelf as it was at the point of using
, even though put
caused the shelf to be saved and a new instance of the shelf created. The saved shelf is what is incremented (to 7). However, the put
outside of the using
prefix refers to the current "version" of the shelf "c", which is the one created by the save-clear
of the element rule (the one triggered by the put
action performed on the #markup-parser
stream).
context-translate global counter c variable initial-size 1 element #implied save-clear c set new c to 25 output "%c" find "A" using c @ 1 do set c to 6 put #markup-parser "<x>xxx" increment c done put #process-output "c = %d(c)%n"
---- |