Difference between revisions of "SCI Programming Language/Definitions"
(→define) |
|||
| Line 26: | Line 26: | ||
==<br /> define == | ==<br /> define == | ||
| + | <blockquote> | ||
The define statement allows you to define a symbol which will stand for a string of text: | The define statement allows you to define a symbol which will stand for a string of text: | ||
| − | (define symbol lots of text) | + | <blockquote><code>(define symbol lots of text)</code></blockquote> |
will replace symbol, wherever it is encountered as a token, with lots of text and then continue scanning at the beginning of the replacement text. Thus, if we write: | will replace symbol, wherever it is encountered as a token, with lots of text and then continue scanning at the beginning of the replacement text. Thus, if we write: | ||
| − | (define symbol some text) | + | <blockquote> |
| − | (define same even more) | + | <code>(define symbol some text)</code><br /> |
| + | <code>(define same even more)</code> | ||
| + | </blockquote> | ||
then: | then: | ||
| − | (symbol) | + | <blockquote><code>(symbol)</code></blockquote> |
will become: | will become: | ||
| − | (some text) | + | <blockquote><code>(some text)</code></blockquote> |
which then becomes: | which then becomes: | ||
| − | (even more text) | + | <blockquote><code>(even more text)</code></blockquote> |
| + | </blockquote> | ||
==<br /> enum == | ==<br /> enum == | ||
Revision as of 22:52, 25 May 2016
define
The define statement allows you to define a symbol which will stand for a string of text:
(define symbol lots of text)will replace symbol, wherever it is encountered as a token, with lots of text and then continue scanning at the beginning of the replacement text. Thus, if we write:
(define symbol some text)
(define same even more)then:
(symbol)will become:
(some text)which then becomes:
(even more text)
enum
The enum statement eases the definition of the various states of a state-variable. Say you want to walk an actor from the door of a room across the floor, up the stairs, and through another door. You have a state-variable called actor-pos which will take on a number of values. These could be defined with defines as follows:
(local actorPos
define AT FRONT DOOR 0)
define IN ROOM 1)
define ON STAIRS 2)
define TOP OF STAIRS 3)
define UPPER DOOR 4)
)or you could get the same result with enum:
(local actor-pos
(enum
AT FRONT DOOR
IN ROOM
ON STAIRS
TOP OF STAIRS
UPPER DOOR
)
)Enum defaults its first symbol to O. If you want a different starting value, put it right after the word enum:
(enum 7
AT FRONT DOOR
IN ROOM
ON STAIRS
TOP OF STAIRS
UPPER DOOR
)sets AT FRONT_ DOOR to 7, IN _ ROOM to 8, etc.
The value of an enum may also be defined by an expression, as follows:
(enum
AT FRONT DOOR = (+ AT REAR DOOR 1)
)Note: Define and enum statements may be included within both global and local variable definitions.
- Notes
< Previous: Data Types and Variables Next: Control Flow >