![]() |
|
||||
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|||||
|
|
|||||
| Related Syntax | Related Concepts | ||||
| action |
set |
||||
Syntax
set ( variable-name indexer?) | (file file-name) to value OR set stream-output-function-call open-modifiers to string-expression
You use set to assign a value to a variable. set replaces the value of a variable with the new value:
set my-stream to "Mary had a little lamb." set my-counter to 78 set my-switch to true set referent "my-referent" to "Its fleece was white as snow." set my-float to 10.56
You can also use set to read and write files:
set file "mary.txt" to my-buffer set my-buffer to file "mary.txt" set file "mary.txt" to file "lamb.txt"
When used with streams, set is equivalent to opening the stream, writing to it, then closing it. For this reason, any modifiers that can be used with open can also be used with set:
set my-stream with referents-allowed defaulting {""}
to "Mary had a little lamb."
set file "mary.txt" with referents-displayed
to my-stream
Set can be used with the open action's modifiers, in particular append. In
the past often times when collecting information programmers would write
set x to x || ", " || new-value
This set action appends the new-value to the end of the buffer attached to
the stream x. It is better to write this as:
set x with append to ", " || new-value
This can also be applied to files, like this:
set file x with append to new-value
Copyright © Stilo International plc, 1988-2008.