Changing a series
Now we will take a look at the action words that are dedicated to changing a series in one way or another—changing, adding, or deleting items.
Changing items – poke, replace, and change
There are two ways to change an item in a series. Let's use data: [A B C D]
, where A
, B
, C
and D
are all words. Suppose we want to replace C
with the word X
. We can do this as follows:
- Binding to a path specified by the item index—for example,
data/3: 'X ;== X
. Nowdata
has become[A B X D]
. Why do we need'X
instead of justX
? The reason is that when you're binding to a word, this word is evaluated. So you have to quote theX
word in order to prevent evaluation. If you don't do this and usedata/3: X
, you'd get aScript Error: X has no value.
- Specifying the item index using
poke
, such aspoke data 3 'X
(the position comes first, then the new value).
(To replace C
with the string "X"
, we just have to use data/3: "X" ;== "X"
; then data
becomes [A B "X" D]
).
What if we want to change an item...