Difference between revisions of "The Script Programming Language/Definitions"

From SCI Wiki
Jump to navigationJump to search
(Created page with "sss")
 
Line 1: Line 1:
sss
+
== <br /> Definitions ==
 +
 
 +
===<br /> define: ===
 +
 
 +
The define statement allows you to define a symbol which will stand for a
 +
string of text:
 +
 
 +
<blockquote>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(define symbol lots of text)
 +
</syntaxhighlight>
 +
</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
 +
 
 +
<blockquote>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(define symbol some text)
 +
(define some even more)
 +
</syntaxhighlight>
 +
</blockquote>
 +
 
 +
then
 +
 
 +
<blockquote>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(symbol)
 +
</syntaxhighlight>
 +
</blockquote>
 +
 
 +
will become
 +
 
 +
<blockquote>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(some text)
 +
</syntaxhighlight>
 +
</blockquote>
 +
 
 +
which then becomes
 +
 
 +
<blockquote>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(even more text)
 +
</syntaxhighlight>
 +
</blockquote>
 +
 
 +
===<br /> enum: ===
 +
 
 +
A construct for easing the definition of various states of a state-variable
 +
is enum.  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, which could be
 +
defined with defines:
 +
 
 +
<blockquote>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(local    actor-pos
 +
    (define at-front-door    0)
 +
    (define in-room          1)
 +
    (define on-stairs        2)
 +
    (define top-of-stairs    3)
 +
    (define upper-door      4)
 +
)
 +
</syntaxhighlight>
 +
</blockquote>
 +
 
 +
or you could get the same result with enum:
 +
 
 +
<blockquote>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(local    actor-pos
 +
    (enum
 +
          at-front-door
 +
          in-room
 +
          on-stairs
 +
          top-of-stairs
 +
          upper-door
 +
    )
 +
)</syntaxhighlight>
 +
</blockquote>
 +
 +
Enum defaults its first symbol to 0.  If you want a different starting
 +
value, put it right after the word enum:
 +
 
 +
<blockquote>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(enum 7
 +
    at-front-door
 +
    in-room
 +
    on-stairs
 +
    top-of-stairs
 +
    upper-door
 +
)
 +
</syntaxhighlight>
 +
</blockquote>
 +
 
 +
sets at-front-door to 7, in-room to 8, etc.
 +
 
 +
===<br /> synonyms: ===
 +
 
 +
The synonyms statement defines synonyms of words.  All words must have been defined in the vocabulary file (see separate Vocabulary documentation).  The statement
 +
 
 +
<blockquote>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(synonyms
 +
    (main-word  synonym1 synonym2 ...)
 +
    ...
 +
)
 +
</syntaxhighlight>
 +
</blockquote>
 +
 
 +
defines the words synonym1, synonym2, etc. to be synonyms of main-word.  In
 +
input being interpreted by the script in which the synonym statement is
 +
defined, user input of synonym1 will be interpreted as if the user had typed
 +
main-word.

Revision as of 17:15, 29 November 2015


Definitions


define:

The define statement allows you to define a symbol which will stand for a string of text:

Code:
(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

Code:
(define symbol some text) 
(define some even more)

then

Code:
(symbol)

will become

Code:
(some text)

which then becomes

Code:
(even more text)


enum:

A construct for easing the definition of various states of a state-variable is enum. 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, which could be defined with defines:

Code:
(local    actor-pos 
     (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:

Code:
(local    actor-pos 
     (enum 
          at-front-door 
          in-room 
          on-stairs 
          top-of-stairs 
          upper-door 
     ) 
)

Enum defaults its first symbol to 0. If you want a different starting value, put it right after the word enum:

Code:
(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.


synonyms:

The synonyms statement defines synonyms of words. All words must have been defined in the vocabulary file (see separate Vocabulary documentation). The statement

Code:
(synonyms 
     (main-word  synonym1 synonym2 ...) 
     ... 
)

defines the words synonym1, synonym2, etc. to be synonyms of main-word. In input being interpreted by the script in which the synonym statement is defined, user input of synonym1 will be interpreted as if the user had typed main-word.