git @ Cat's Eye Technologies Wanda / 94dfec4
Some edits. Chris Pressey 3 years ago
1 changed file(s) with 11 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
00 Wanda
11 =====
22
3 Wanda is a Forth-like language. Despite being Forth-like, it seems unfair
4 to call it "concatenative", or even "stack-based", because it is based
5 on a string-rewriting semantics.
3 Wanda is a "concatenative" language that's not actually "concatenative"
4 at all, nor even "stack-based", because it's based on a string-rewriting
5 semantics.
66
77 The remainder of this document will describe the language and will attempt
88 to justify the above statement.
4141 pattern `X Y $ +`, where X and Y are integers; the part of the string that
4242 matches that pattern is replaced by a single integer which is the sum of
4343 X and Y, followed by a `$`.
44
45 If no patterns match anywhere in the string, the expression remains unchanged
46 and evaluation terminates.
47
48 2 $ +
49 ===> 2 $ +
5044
5145 You can think of `$` as a symbol which delineates the stack (on the left)
5246 from the program (on the right). When constants are encountered in the
5953 stack, nor an instruction that pushes the value 2 onto the stack; it's just
6054 a `2`.
6155
56 Indeed, observe that, if no patterns match anywhere in the string, the
57 expression remains unchanged and evaluation terminates:
58
59 2 $ +
60 ===> 2 $ +
61
6262 ### Some other builtins
6363
64 We've seen `+` and `*`, which are built-in rules.
65 There are a couple of other built-in rules.
64 We've seen `+` and `*`, which are built-in functions (or rules).
65 There are a couple of other built-in functions (or rules).
6666
6767 $ 7 sgn 0 sgn -14 sgn
6868 ===> 1 0 -1 $