operator
shelf lastmost
lastmost
can be used to identify a shelf item to be accessed, wherever an item
indexer, [...]
or key {...}
can be used. The lastmost
indexer always
accesses the last item on the shelf.
Note that the syntaxes shelf lastmost
and shelf[number of
shelf]
are identical when used to access an item on a shelf. They behave differently when they
are used to set the currently selected item:
using
prefix, and
modifiable
, read-only
, or
write-only
argument.
lastmost
item is recalculated, while number of
is not. This means that when the default item is set
to lastmost
, it will always be the last item on the shelf, regardless of how the shelf changes.
In this example, which uses lastmost
,
process local integer c variable clear c set new c to 1 using c lastmost do output "The value is %d(c)%n" set new c to 2 output "The value is %d(c)%n" set new c to 3 output "The value is %d(c)%n" donethe output is:
The value is 1 The value is 2 The value is 3However, when the default is set to the last item with
[number of c]
:
process local integer c variable clear c set new c to 1 using c [number of c] do output "The value is %d(c)%n" set new c to 2 output "The value is %d(c)%n" set new c to 3 output "The value is %d(c)%n" donethe output is:
The value is 1 The value is 1 The value is 1This is because the number of items on shelf c is just
1
. That becomes the numeric index of the
shelf for the duration of using
.
Note that it cannot be assumed that the lastmost item of a passed shelf is its current item. The following
function takes this possibility into account, and the using
keyword is used to ensure that references
to the stream code-set
refer only to the newly created item.
define function add-new-codes (modifiable stream code-set, value string new-codes) as using code-set lastmost do new code-set open code-set as buffer repeat scan new-codes match letter => one-code put code-set "%ux(one-code)" match any ; skip again close code-set done