SketchyLISP Reference Manual - Copyright (C) 2005 Nils M Holm
Previous: Summary | - Contents - Index - | Next: Reduction Rules |
Each SketchyLISP expression is a program and each program is an expression. Programs are 'executed' by reducing them to their normal forms. No input/output routines exist, but the interpreter prints the normal form of each expression which has been reduced at the top level. The context of an expression is the top level, if the expression has been entered at the user's terminal.
The interpreter makes no difference between upper and lower case characters, but it folds all input to lower case.
There are multiple types of SketchyLISP expressions:
The special object ()
represents the
empty list.
Symbols, booleans, procedures, numbers, chars, and strings are called atoms or atomic expressions, because they cannot be decomposed.
A symbol is represented by a name composed of these ASCII characters:
abcdefghijklmnopqrstuvwxyz 0123456789 * + - / < = > _ ? !
A pair is a set of two expressions represented by the form
(x . y)
where x and y may be of any type. The x part of a pair is also called its car part and the y part is called its cdr part part. A pair is also said to be of the type cons.
Note that the Scheme standard requires a blank character before and after the dot separating the car and cdr part of a pair. SketchyLISP does not require this blank, so above pair could be written as:
(x.y)
This notation will also be used in this document.
A list is a pair whose cdr field is
either another pair or ()
. The only exception is
the empty list which does not have a car nor a cdr part. Each list
of the form
(a1 . (a2 . ... (aN . ()) ... ))
may also be written as
(a1 a2 ... aN)
The second form is equivalent to the first one, but easier to read.
Lists whose last members are not equal to ()
are called improper lists.
Such lists have an atom in their last position. They are represented
using pair notation:
(a b . c)
or
(a b.c)
The boolean literal
#t
represents logical truth and
#f
represents logical falsity.
Integer
numbers (or just integers
)
are represented by lists of digits with an optional leading plus or minus
sign, eg:
314 -159 +265
Integers are the only numbers in SketchyLISP, so the terms integer
and number
are used as synonyms in this document.
Character literals (or just chars
)
are introduced by the prefix #\
. The character to be
represented follows without any blanks in between, for instance:
#\A #\b #\" #\\ #\# #\(
The blank character may be written as #\
, but for
improved readability, the notation #\space
should be
preferred.
String literals (or just strings
)
are sequences of printable characters (including blanks) which are delimited
by double quotes ("
):
"abc" "Foo" "Hello, World!" "\"Hi,\" she said."
As shown above, quote characters may be included in strings by
escaping
them. A character is escaped
by prefixing it with a backslash (\
). To include the
backslash itself in a string, it must be escaped with another backslash:
"A \\ B"
Procedures are represented by lambda functions
of the form
(lambda (args) term)
They will be explained in detail in the following chapters.
At any point, a comment may be
placed in an expression by inserting a semicolon (;
).
Each comment extends up to the end of the line it has been started in.
All characters are allowed in comments. To the interpreter, the entire
comment looks like a single space character.
Any expression prefixed with '
is in its
normal form
. The interpreter displays normal forms in this way.
Previous: Summary | - Contents - Index - | Next: Reduction Rules |