git @ Cat's Eye Technologies stringie / 19b2cd2
Add a description of Underload, so you know what you're getting into. Chris Pressey 3 years ago
2 changed file(s) with 102 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 _UAEFSDB.___
01 bin/stringie
12 *.o
0 Underload
1 =========
2
3 (This document was converted from the public-domain HTML Underload
4 specification in The Esoteric File Archive.)
5
6 Basics
7 ------
8
9 Underload is a stack-based programming language that works along similar
10 lines to Muriel. Although not technically speaking a functional
11 language, its evaluation operator ^ (which is the only form of flow
12 control) makes programming in it functional in practice.
13
14 Reserved characters
15 -------------------
16
17 The bracket and angle bracket characters []<> are reserved; if these are
18 to appear anywhere in the program, they must be quoted by placing "
19 before them. This also applies to the " character itself. Other
20 characters must _not_ be quoted with " (in particular, this means that
21 Underload programs cannot output strings containing unmatched
22 parentheses). Parentheses are moderately reserved, in that any Underload
23 program must have matched parentheses to be legal.
24
25 Commands
26 --------
27
28 - ~ Swap the top two elements of the stack.
29 - : Duplicate the top element of the stack.
30 - ! Discard the top element of the stack.
31 - * Concatenate the top element of the stack to the end of the second
32 element of the stack.
33 - ( Push everything between the ( and the matching ) on top of
34 the stack.
35 - ) Closes a ( command.
36 - a Encloses the top element of the stack in a pair of parentheses.
37 - ^ When the ^ command is called, it includes the top element of the
38 stack into the program, immediately after the ^ command, ready to be
39 run next.
40 - S Output the top element of the stack, popping it.
41
42 Exceptional circumstances
43 -------------------------
44
45 Pretty much anything whose behaviour isn't specifically given here (for
46 instance, running * on an empty stack) is an error.
47
48 Unlambda to Underload
49 ---------------------
50
51 The s, k, and i characters in Unlambda can all be translated directly
52 into Underload. Also, the ` character can be translated, but it has to
53 be moved to a postfix rather than prefix position, and .x can be
54 translated for most values of _x_.
55
56 - s translates to ((:)~*(~)*a(~*(~^)*)):
57 sx`y`z` = xz`yz`` (postfix notation)
58 sx`y`   = (:x~y~^)
59 sx`     = ((:x~)~*(~^)*)
60 s       = ((:)~*(~)*a(~*(~^)*)*)
61 - k translates to (a(!)~*)
62 - i translates to ()
63 - ` translates to ~^
64 - .x translates to ((x)S)
65
66 These translations prove that Underload is Turing-complete, because it
67 can be compiled into from the Turing-complete `sk Unlambda.
68
69 Example programs
70 ----------------
71
72 ### Hello, world!
73
74 (Hello, world!)S
75
76 ### Fibonacci sequence
77
78 (()(*))(~:^:S*a~^a~!~*~:(/)S^):^
79
80 (An ski`. Unlambda version is
81 ```s``s``sii`ki`k.*``s``s`ks``s`k`s`ks``s``s`ks``s`k`s`k./``s`k`sikk`k``s`ksk,
82 which can also be loaded up in the interpreter below by clicking on it;
83 you can automatically convert it to Underload if you wish to run it.)
84
85 ### Infinite loop
86
87 (:^):^
88
89 (This is exactly equivalent to the ski`. Unlambda program ```sii``sii;
90 if the Unlambda program is converted to Underload using the compiler
91 below and run for a while, it eventually ends up in the same state as
92 the previous Underload program (the only difference being ~~, which has
93 no effect, in the code derived from the Unlambda).
94
95 ### Quine
96
97 (:aSS):aSS
98
99 (The null program is also a quine. This program is more stack-based than
100 functional.)