Skip to main content

Storing into Containers

The put, set, and get commands are used to store values into containers. Several other commands will also change the value in a container.

put, set commands

The put ... into command is used to assign a value to a container:

put 5 into count
put true into global peace
put customerName into word 2 of line 6 of customerStatement

The set command can do the same thing:

set count = 5
set global peace to be true
set word 2 of line 6 of customerStatement to customerName

Syntax:

put source into container

set container [= | to {be {equal to}} | equal] source

Appending Values

The put command (but not set) can also append values at the beginning or end of a container, by specifying before or after instead of into:

put "flower" into wordToMakePlural -- flower
put "s" after wordToMakePlural -- flowers
put heading & return before reportBody
put " " & customerLastName after word 2 of line 6 of customerStatement
put "$" before character firstDigit of Amount

Syntax:

put source [before | after] container

Storing Multiple Values At Once

Both the put and set commands can store values into several containers at once. To do this, list the containers separated by commas and enclosed in square brackets. If the source value is a single non-list value, that value will be assigned to all of the destination containers:

put zero into [a,b,c] -- sets a, b, and c all to zero
set [startTime, endTime] to "noon"

If the source value is a list, consecutive items from the source list will be assigned to each of the destination containers in turn. Excess values will be ignored:

put [1,2,3] into [a,b,c] -- sets a to 1, b to 2, and c to 3
set [x,y] to [y,x]-- swaps the values of x and y

Source values will be skipped if no container is provided to store them into:

put [1,2,3] into [a,,c] -- sets a to 1, and c to 3 (2 is ignored)
put "html://foo/bar" split by "/" into [scheme,,root,leaf]

Extra values at the end of the source list can be gathered into a single container by using "..." (three dots) after the final container:

put [1,2,3,4] into [a,b...] -- sets a to 1, and b to (2,3,4)

turn on, turn off commands

These commands set the value of a container to on or off:

turn the caseSensitive on

turn off bit 1 of rootflags

Syntax:

turn [on | off] container

turn container [on | off]

get command

The get command offers another way to access a value, which can then be referred to as it:

get the last word of address
if it is "DC" then shipNow
note

It is actually a local variable that is also stored into by several other commands besides get, including the ask, answer, convert, and read commands and the "repeat with each" form of the repeat command (see All About "It").

Syntax:

get source

Other Commands Modify Container Values

Several other commands will also change the contents of containers, including the add, subtract, multiply, divide, insert, replace, and delete commands, and certain forms of a number of other commands including the convert, read, sort, split, and join commands:

add qty to item productNum of inventoryQty
divide profit by shareholderCount
convert lastUpdate to long date