blob: dde4890f39117fd7768bd1fd2e71c2d9154cb6c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
### How to implement a minimal scheme?
Potentially need an AST-like data structure representing the parsed expression.
This is the s-expression. Well represented as a pair with value types:
null
pair
boolean (true/false)
number
identifier/symbol
One way to accomplish the above would be to use a pair datatype in the host
language. Another is to try to use tuples or lists; this will result in faster
execution but is much harder?
'value' and other high level functions will take an s-expr and return an
s-expr. eval wraps this with an AST parse at the begining and a pretty print at
the end.
'meaning' takes an s-expr object and a context/environment and computes the
result s-expr. it recursively looks at each node in the s-expr, decides what
action needs to be taken on it, and executes the action. possible actions (aka,
parsed types) are:
const (atomic values)
lambda
quote (s-expr "one level down")
identifier (a symbol to be looked up in the context)
cond (conditional expression)
The specific list of "special"/"built-in"/"reserved" identifiers is:
lambda
quote
cond
else
cons
car
cdr
null?
eq?
atom?
zero?
number?
Things which an be applied are lambdas and the above built-ins.
When applying a lambda, need to bind values to local context. This requires
an immutable or copied lookup table.
|