|
|||||
|
|||||
Related Syntax | Related Concepts | ||||
action |
new |
Syntax
new shelf-name ({string-expression})? insertion-point? set new shelf-name ({ string-expression})? insertion-point? to expression
Argument definitions
new
inserts a new item onto a shelf and can only be invoked on shelves that have been declared variable
:
local integer x variable initial-size 0 new x
By default, the new item is inserted after the last item on the shelf. You can insert the new item before or after another item:
new x{"wilma"} after [2]
To make the new item the first item on the shelf, you can use before [1]
or after [0]
.
A new item can be given a key as it is inserted:
new x{"fred"} before {"barney"} new x{"wilma"} after [2]
The set new
action combines the new
and set
actions into one action so that
new x{"fred"} before [1] set x{"fred"} to "flintstone0"can be replaced with:
set new x{"fred"} before [1] to "flintstone0"
Putting these code fragments together gives us the following program:
process local stream x variable initial-size 0 new x set key of x to "barney" set x to "flintstone1" set new x{"fred"} before [1] to "flintstone0" set x{"fred"} to "flintstone0" new x{"wilma"} after [2] set x{"wilma"} to "flintstone2" repeat over x output x || " has key " || key of x || "%n" again ; Output: "flintstone0 has key fred ; flintstone1 has key barney ; flintstone2 has key wilma"
Related Syntax set |
Related Concepts Shelves Variables |