Differences From Artifact [7d7a59abebf26f18]:
- File
readme.txt
- 2010-11-09 15:48:55 - part of checkin [9eec42eba1] on branch trunk - memo (user: kinaba) [annotate]
To Artifact [b45d599d08f18ee0]:
- File
readme.txt
- 2010-11-20 09:20:03 - part of checkin [515502e8d1] on branch trunk - table get, init, ask expressions addded (user: kinaba) [annotate]
1 ----------------------------------------------------------------------------- 1 -----------------------------------------------------------------------------
2 Polemy 0.1.0 2 Polemy 0.1.0
3 by k.inaba (www.kmonos.net) 3 by k.inaba (www.kmonos.net)
4 Nov 8, 2010 | 4 Nov 20, 2010
5 ----------------------------------------------------------------------------- 5 -----------------------------------------------------------------------------
6 6
7 7
8 8
9 <<How to Build>> 9 <<How to Build>>
10 10
11 - Install DMD 11 - Install DMD
12 http://www.digitalmars.com/d/2.0/changelog.html 12 http://www.digitalmars.com/d/2.0/changelog.html
13 Version 2.050 is recommended. Older and/or newer version may not work. | 13 Version 2.050 is recommended. Older or newer version may not work.
14 14
15 - Build 15 - Build
16 (for Windows) Run build.bat 16 (for Windows) Run build.bat
17 (for Unix) Run build.sh 17 (for Unix) Run build.sh
18 or use your favorite build tools upon main.d and polemy/*.d. 18 or use your favorite build tools upon main.d and polemy/*.d.
19 19
20 Then you will get the executable "polemy" in the "bin" directory. 20 Then you will get the executable "polemy" in the "bin" directory.
................................................................................................................................................................................
43 43
44 > polemy 44 > polemy
45 starts REPL 45 starts REPL
46 46
47 > polemy foo.pmy 47 > polemy foo.pmy
48 executes foo.pmy 48 executes foo.pmy
49 49
> 50 > polemy -l foo.pmy
> 51 after executing foo.pmy, starts REPL
50 52
51 53
52 <<Memo of Language Spec>> <
53 54
54 syntax | 55 <<Syntax>>
55 56
> 57 Comment is "# ... \n"
> 58
> 59 E ::=
> 60 // declaration
> 61 | ("var"|"let"|"def"|LAYER) ID "=" E (";"|"in") E
> 62 | ("var"|"let"|"def"|LAYER) ID "(" PARAMS ")" "{" E "}" (";"|"in") E
56 E ::= ("var"|"let"|"def"|LAYER) ID "=" E ; E | 63 | ("var"|"let"|"def"|LAYER) ID "=" E
> 64 | ("var"|"let"|"def"|LAYER) ID "(" PARAMS ")" "{" E "}"
> 65 // literal
> 66 | INTEGER
> 67 | STRING
> 68 | "{" ENTRYS "}"
57 | "fun" "(" PARAMS ")" "{" E "}" 69 | "fun" "(" PARAMS ")" "{" E "}"
> 70 // function call
58 | E "(" ARGS ")" | 71 | E "(" ARGS")"
59 <
> 72 where ARGS ::= E "," ... "," E
> 73 PARAMS ::= ID LAYER* "," ... "," ID LAYER*
> 74 ENTRYS ::= ID ":" E "," ... "," ID ":" E
> 75 ID ::= 'a-zA-Z0-9_...'+
60 | LAYER "(" E ")" | 76 LAYER ::= "@" ID
61 <
> 77 // operators
62 | "(" E ")" 78 | "(" E ")"
> 79 | E "." ID
> 80 | E ".?" ID
63 | E BINOP E 81 | E BINOP E
64 | "if" "(" E ")" "{" E "}" 82 | "if" "(" E ")" "{" E "}"
65 | "if" "(" E ")" "{" E "}" "else "{" E "}" 83 | "if" "(" E ")" "{" E "}" "else "{" E "}"
66 | ("var"|"let"|"def"|LAYER) ID "(" PARAMS ")" "{" E "}" | 84 // layered exec
> 85 | LAYER "(" E ")"
> 86
> 87 The following are actually rewritten to function calls:
> 88
> 89 - if (E) then{E} else{E} ==> if( E, fun(){E}, fun(){E} )
> 90 - E BINOP E ==> BINOP(E, E)
> 91 - E.ID ==> . (E, ID)
> 92 - E.?ID ==> .?(E, ID)
> 93 - {} ==> {}()
> 94 - {ID:E, ...} ==> .=({...}, ID, E)
> 95
> 96 Several styles of variable declaration can be used:
> 97
> 98 - fun(x){ fun(y){x} } # K-combinator
> 99 - fun(x){ let f = fun(y){x} in f } # let-in style
> 100 - fun(x){ var f = fun(y){x}; f } # var-; style
> 101 - fun(x){ def f = fun(y){x} in f } # you can use any combination of (let|var|
> 102 - fun(x){ def f(y){x} in f } # syntax sugar for function declaration
> 103 - fun(x){ let f(y){x}; f } # this is also ok
> 104 - fun(x){ var f(y){x} } # omitting (;|in) returns the last declared objec
> 105 - fun(x,y){x} #< this is not equal to the above ones. functions are no curried
> 106
> 107 NOTE: Theres no "let rec" syntax, but still recursive definition works
> 108 def f(x) { if(x==0){1}else{x*f(x-1)} } in f(10) #=> 3628800
> 109 yet still the code below also works
> 110 def x=21 in def x=x+x in x #=> 42.
> 111 The internal scoping mechanism is a little tricky (this is for coping with
> 112 the "layer" feature explained below), but I hope that it works as everyone
> 113 expects in most cases, as long as you don't use the same-name-variables heavil
> 114
> 115
67 116
68 ARGS ::= ","-separated E's | 117 <<Basic Features>>
69 PARAMS ::= ","-separated VAR's <
70 LAYER ::= "@" ID <
71 118
72 if-then-else is a syntax sugar for a function call: if( E, fun(){E}, fun(){E} ) | 119 Polemy is an untyped functional programming language that has
73 binary ops (e.g., E + E) is a syntax sugar: +(E, E) | 120 - integers: 0, 123, 456666666666666666666666666666666666666789, ...
> 121 - strings: "hello, world!\n", ...
> 122 - tables: {car: 1, cdr: {car: 2, cdr: {}}}
> 123 - functions: fun(x){x+1}
> 124 as primitive datatypes. Functions capture lexical closures.
> 125 It is almost 'pure' (except the primitve function "print" and some
> 126 trick inside scoping mechanisms).
> 127
74 128
75 comment is "# ... \n" | 129 <<Layer>>
76 130
> 131 to be written