Difference between revisions of "SCI Programming Language/Definitions"

From SCI Wiki
Jump to navigationJump to search
 
(8 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
<div align="center">
 
<div align="center">
 
Chapter:  
 
Chapter:  
[[The SCI Programming Language/Introduction|1]] |  
+
[[SCI Programming Language/Introduction|1]] |  
[[The SCI Programming Language/Primitive Procedures|2]] |  
+
[[SCI Programming Language/Primitive Procedures|2]] |  
[[The SCI Programming Language/Arithmetic Primitives|3]] |  
+
[[SCI Programming Language/Primitive_Procedures#Arithmetic_Primitives|3]] |  
[[The SCI Programming Language/Boolean Primitives|4]] |  
+
[[SCI Programming Language/Primitive_Procedures#Boolean_Primitives|4]] |  
[[The SCI Programming Language/Assignment Primitives |5]] |  
+
[[SCI Programming Language/Primitive_Procedures#Assignment_Primitives |5]] |  
[[The SCI Programming Language/Data Types and Variables|6]] |  
+
[[SCI Programming Language/Data Types and Variables|6]] |  
[[The SCI Programming Language/Definitions|7]] |  
+
[[SCI Programming Language/Definitions|7]] |  
[[The SCI Programming Language/Control Flow|8]] |  
+
[[SCI Programming Language/Control Flow|8]] |  
[[The SCI Programming Language/Conditionals|9]] |  
+
[[SCI Programming Language/Control Flow#Conditionals|9]] |  
[[The SCI Programming Language/Iteration|10]] |  
+
[[SCI Programming Language/Control Flow#Iteration|10]] |  
[[The SCI Programming Language/Procedures|11]] |  
+
[[SCI Programming Language/Procedures|11]] |  
[[The SCI Programming Language/Files|12]] |  
+
[[SCI Programming Language/Files|12]] |  
[[The SCI Programming Language/Compiling SCI|13]] |  
+
[[SCI Programming Language/Compiling SCI|13]] |  
[[The SCI Programming Language/Index|Index]]
+
[[SCI Programming Language/Index|Index]]
 
</div><br />
 
</div><br />
  
<div align="center"><span style="font-size: 22pt">x</span><br />
+
<div align="center"><span style="font-size: 22pt">Definitions</span><br />
 
''Author: [[Jeff Stephenson]]''</div>
 
''Author: [[Jeff Stephenson]]''</div>
  
 
&nbsp;
 
&nbsp;
 +
 +
==<br /> define ==
 +
 +
<blockquote>
 +
The define statement allows you to define a symbol which will stand for a string 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:
 +
 +
<blockquote>
 +
<code>(define symbol some text)</code><br />
 +
<code>(define same even more)</code>
 +
</blockquote>
 +
 +
then:
 +
 +
<blockquote><code>(symbol)</code></blockquote>
 +
 +
will become:
 +
 +
<blockquote><code>(some text)</code></blockquote>
 +
 +
which then becomes:
 +
 +
<blockquote><code>(even more text)</code></blockquote>
 +
</blockquote>
 +
 +
==<br /> enum ==
 +
<blockquote>
 +
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:
 +
 +
<blockquote>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(local actorPos
 +
  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 O. 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 <code>AT FRONT_ DOOR</code> to 7, <code>IN _ ROOM</code> to 8, etc.
 +
 +
The value of an enum may also be defined by an expression, as follows:
 +
 +
<blockquote>
 +
<div class="CodeBlockHeader">Code:</div>
 +
<syntaxhighlight lang="sci">
 +
(enum
 +
  AT FRONT DOOR = (+ AT REAR DOOR 1)
 +
)
 +
</syntaxhighlight>
 +
</blockquote>
 +
 +
Note: Define and enum statements may be included within both global and local variable definitions.
 +
</blockquote>
 +
 +
;Notes
 +
<references />
 +
 +
[[SCI Programming Language | Table of Contents]]
 +
 +
<span style="float: left">[[SCI Programming Language/Data Types and Variables|&lt; Previous: Data Types and Variables]]</span>
 +
<span style="float: right">[[SCI Programming Language/Control Flow|Next: Control Flow &gt;]]</span>
 +
 +
&nbsp;
 +
 +
[[Category:SCI Documentation]]
 +
[[Category:SCI32]]
 +
[[Category:Scripting]]

Latest revision as of 22:54, 25 May 2016

Official SCI Documentation

Chapter: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Index


Definitions
Author: Jeff Stephenson

 


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:

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

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

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.

The value of an enum may also be defined by an expression, as follows:

Code:
(enum
   AT FRONT DOOR = (+ AT REAR DOOR 1)
)

Note: Define and enum statements may be included within both global and local variable definitions.

Notes


Table of Contents

< Previous: Data Types and Variables Next: Control Flow >