コンテナに保存
put、set、そしてgetコマンドは、コンテナに値を保存するために使用されます。他のいくつかのコマンドもコンテナ内の値を変更します。
put、setコマンド
put ... intoコマンドは、コンテナに値を割り当てるために使用されます:
put 5 into count
put true into global peace
put customerName into word 2 of line 6 of customerStatement
setコマンドも同じことができます:
set count = 5
set global peace to be true
set word 2 of line 6 of customerStatement to customerName
文法:
put source into container set container [= | to {be {equal to}} | equal] source
値の追加
putコマンド(setではない)は、intoの代わりにbeforeまたはafterを指定することで、コンテナの先頭または末尾にも値を追加することができます:
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
文法:
put source [before | after] container
複数の値を一度に保存する
putとsetの両方のコマンドは、一度に複数のコンテナに値を保存することができます。これを行うため には、コンテナをカンマで区切り、角括弧で囲みます。ソースの値が単一の非リスト値である場合、その値はすべての宛先コンテナに割り当てられます:
put zero into [a,b,c] -- sets a, b, and c all to zero
set [startTime, endTime] to "noon"
ソース値がリストの場合、ソースリストの連続するアイテムが順番に各宛先コンテナに割り当てらられます。余分な値は無視されます:
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
格納するコンテナが提供されていない場合、ソース値はスキップされます:
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]
ソースリストの末尾にある追加の値は、最後のコンテナの後に"..."(三つの点)を使用することで、単一のコンテナに収集することができます:
put [1,2,3,4] into [a,b...] -- sets a to 1, and b to (2,3,4)
turn on, turn offコマンド
これらのコマンドは、コンテナの値をonまたはoffに設定します:
turn the caseSensitive on
turn off bit 1 of rootflags
md 構文:
turn [on | off] container turn container [on | off]
getコマンド
getコマンドは、値にアクセスするための別の方法を提供し、それはその後itとして参照することができます:
get the last word of address
if it is "DC" then shipNow
Itは実際には、getの他にもask、answer、convert、readコマンドやrepeatコマンドの"repeat with each"形式など、他のいくつかのコマンドによって格納されるローカル変数です(すべてについて "It"参照)。
文法:
get source
他のコマンドによるコンテナ値の変更
いくつかの他のコマンドもまた、コンテナの内容を変更します。これにはadd、subtract、multiply、divide、insert、replace、deleteコマンド、およびconvert、read、sort、split、joinコマンドなどの他の多くのコマンドの特定の形式が含まれます:
add qty to item productNum of inventoryQty
divide profit by shareholderCount
convert lastUpdate to long date