Some edits.
Chris Pressey
6 years ago
0 | 0 | Wanda |
1 | 1 | ===== |
2 | 2 | |
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. | |
6 | 6 | |
7 | 7 | The remainder of this document will describe the language and will attempt |
8 | 8 | to justify the above statement. |
41 | 41 | pattern `X Y $ +`, where X and Y are integers; the part of the string that |
42 | 42 | matches that pattern is replaced by a single integer which is the sum of |
43 | 43 | 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 $ + | |
50 | 44 | |
51 | 45 | You can think of `$` as a symbol which delineates the stack (on the left) |
52 | 46 | from the program (on the right). When constants are encountered in the |
59 | 53 | stack, nor an instruction that pushes the value 2 onto the stack; it's just |
60 | 54 | a `2`. |
61 | 55 | |
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 | ||
62 | 62 | ### Some other builtins |
63 | 63 | |
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). | |
66 | 66 | |
67 | 67 | $ 7 sgn 0 sgn -14 sgn |
68 | 68 | ===> 1 0 -1 $ |