Diff
Not logged in

Differences From Artifact [7d7a59abebf26f18]:

To Artifact [b45d599d08f18ee0]:


1 1 ----------------------------------------------------------------------------- 2 2 Polemy 0.1.0 3 3 by k.inaba (www.kmonos.net) 4 - Nov 8, 2010 4 + Nov 20, 2010 5 5 ----------------------------------------------------------------------------- 6 6 7 7 8 8 9 9 <<How to Build>> 10 10 11 11 - Install DMD 12 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 15 - Build 16 16 (for Windows) Run build.bat 17 17 (for Unix) Run build.sh 18 18 or use your favorite build tools upon main.d and polemy/*.d. 19 19 20 20 Then you will get the executable "polemy" in the "bin" directory. ................................................................................ 43 43 44 44 > polemy 45 45 starts REPL 46 46 47 47 > polemy foo.pmy 48 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 56 - E ::= ("var"|"let"|"def"|LAYER) ID "=" E ; E 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 63 + | ("var"|"let"|"def"|LAYER) ID "=" E 64 + | ("var"|"let"|"def"|LAYER) ID "(" PARAMS ")" "{" E "}" 65 + // literal 66 + | INTEGER 67 + | STRING 68 + | "{" ENTRYS "}" 57 69 | "fun" "(" PARAMS ")" "{" E "}" 58 - | E "(" ARGS ")" 59 - 60 - | LAYER "(" E ")" 61 - 70 + // function call 71 + | E "(" ARGS")" 72 + where ARGS ::= E "," ... "," E 73 + PARAMS ::= ID LAYER* "," ... "," ID LAYER* 74 + ENTRYS ::= ID ":" E "," ... "," ID ":" E 75 + ID ::= 'a-zA-Z0-9_...'+ 76 + LAYER ::= "@" ID 77 + // operators 62 78 | "(" E ")" 79 + | E "." ID 80 + | E ".?" ID 63 81 | E BINOP E 64 82 | "if" "(" E ")" "{" E "}" 65 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|def)-(;|in) 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 object directly 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 heavily :). 114 + 115 + 67 116 68 -ARGS ::= ","-separated E's 69 -PARAMS ::= ","-separated VAR's 70 -LAYER ::= "@" ID 117 +<<Basic Features>> 71 118 72 -if-then-else is a syntax sugar for a function call: if( E, fun(){E}, fun(){E} ) 73 -binary ops (e.g., E + E) is a syntax sugar: +(E, E) 119 + Polemy is an untyped functional programming language that has 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