Artifact 6629940451babbd38ec926b9d5212dbb65c9fd3a
1 -----------------------------------------------------------------------------
2 Polemy 0.1.0
3 by k.inaba (www.kmonos.net)
4 Nov 20, 2010
5 -----------------------------------------------------------------------------
6
7
8
9 <<How to Build>>
10
11 - Install DMD
12 http://www.digitalmars.com/d/2.0/changelog.html
13 Version 2.050 is recommended. Older or newer version may not work.
14
15 - Build
16 (for Windows) Run build.bat
17 (for Unix) Run build.sh
18 or use your favorite build tools upon main.d and polemy/*.d.
19
20 Then you will get the executable "polemy" in the "bin" directory.
21
22
23
24 <<License>>
25
26 d2stacktrace/*
27
28 is written by Benjamin Thaut and licensed under 2-clause BSD License.
29 See http://3d.benjamin-thaut.de/?p=15 for the detail.
30
31 (this package is used only for enabling stack-traces during printing exceptions;
32 it is not used for release builds.)
33
34 polemy/*
35 main.d
36
37 All the other parts are written by Kazuhiro Inaba and
38 licensed under NYSL 0.9982 ( http://www.kmonos.net/nysl/ ).
39
40
41
42 <<How to Use>>
43
44 > polemy
45 starts REPL
46
47 > polemy foo.pmy
48 executes foo.pmy
49
50 > polemy -l foo.pmy
51 after executing foo.pmy, starts REPL
52
53 > polemy -l foo.pmy -l bar.pmy buz.pmy
54 executes foo.pmy, bar.bmy, and then buz.pmy
55
56
57
58 <<Syntax>>
59
60 Comment is "# ... \n"
61
62 E ::=
63 // declaration
64 | ("var"|"let"|"def"|LAYER) ID "=" E (";"|"in") E
65 | ("var"|"let"|"def"|LAYER) ID "(" PARAMS ")" "{" E "}" (";"|"in") E
66 | ("var"|"let"|"def"|LAYER) ID "=" E
67 | ("var"|"let"|"def"|LAYER) ID "(" PARAMS ")" "{" E "}"
68 // literal
69 | INTEGER
70 | STRING
71 | "{" ENTRYS "}"
72 | "fun" "(" PARAMS ")" "{" E "}"
73 // function call
74 | E "(" ARGS")"
75 where ARGS ::= E "," ... "," E
76 PARAMS ::= ID LAYER* "," ... "," ID LAYER*
77 ENTRYS ::= ID ":" E "," ... "," ID ":" E
78 ID ::= 'a-zA-Z0-9_...'+
79 LAYER ::= "@" ID
80 // operators
81 | "(" E ")"
82 | E "." ID
83 | E ".?" ID
84 | E BINOP E
85 | "if" "(" E ")" "{" E "}"
86 | "if" "(" E ")" "{" E "}" "else "{" E "}"
87 // layered exec
88 | LAYER "(" E ")"
89
90 The following are actually rewritten to function calls:
91
92 - if (E) then{E} else{E} ==> if( E, fun(){E}, fun(){E} )
93 - E BINOP E ==> BINOP(E, E)
94 - E.ID ==> . (E, ID)
95 - E.?ID ==> .?(E, ID)
96 - {} ==> {}()
97 - {ID:E, ...} ==> .=({...}, ID, E)
98
99 Several styles of variable declaration can be used:
100
101 - fun(x){ fun(y){x} } # K-combinator
102 - fun(x){ let f = fun(y){x} in f } # let-in style
103 - fun(x){ var f = fun(y){x}; f } # var-; style
104 - fun(x){ def f = fun(y){x} in f } # you can use any combination of (let|var|def)-(;|in)
105 - fun(x){ def f(y){x} in f } # syntax sugar for function declaration
106 - fun(x){ let f(y){x}; f } # this is also ok
107 - fun(x){ var f(y){x} } # omitting (;|in) returns the last declared object directly
108 - fun(x,y){x} #< this is not equal to the above ones. functions are no curried.
109
110 NOTE: Theres no "let rec" syntax, but still recursive definition works
111 def f(x) { if(x==0){1}else{x*f(x-1)} } in f(10) #=> 3628800
112 yet still the code below also works
113 def x=21 in def x=x+x in x #=> 42.
114 The internal scoping mechanism is a little tricky (this is for coping with
115 the "layer" feature explained below), but I hope that it works as everyone
116 expects in most cases, as long as you don't use the same-name-variables heavily :).
117
118
119
120 <<Basic Features>>
121
122 Polemy is an untyped functional programming language that has
123 - integers: 0, 123, 456666666666666666666666666666666666666789, ...
124 - strings: "hello, world!\n", ...
125 - tables: {car: 1, cdr: {car: 2, cdr: {}}}
126 - functions: fun(x){x+1}
127 as primitive datatypes. Functions capture lexical closures.
128 It is almost 'pure' (except the primitve function "print" and some
129 trick inside scoping mechanisms).
130
131
132 <<Layer>>
133
134 to be written