423f308350 2010-11-07 kinaba: ----------------------------------------------------------------------------- 423f308350 2010-11-07 kinaba: Polemy 0.1.0 423f308350 2010-11-07 kinaba: by k.inaba (www.kmonos.net) 515502e8d1 2010-11-20 kinaba: Nov 20, 2010 423f308350 2010-11-07 kinaba: ----------------------------------------------------------------------------- 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: <<How to Build>> 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: - Install DMD 423f308350 2010-11-07 kinaba: http://www.digitalmars.com/d/2.0/changelog.html 515502e8d1 2010-11-20 kinaba: Version 2.050 is recommended. Older or newer version may not work. 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: - Build 423f308350 2010-11-07 kinaba: (for Windows) Run build.bat 423f308350 2010-11-07 kinaba: (for Unix) Run build.sh 423f308350 2010-11-07 kinaba: or use your favorite build tools upon main.d and polemy/*.d. 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: Then you will get the executable "polemy" in the "bin" directory. 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: <<License>> 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: d2stacktrace/* 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: is written by Benjamin Thaut and licensed under 2-clause BSD License. 423f308350 2010-11-07 kinaba: See http://3d.benjamin-thaut.de/?p=15 for the detail. 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: (this package is used only for enabling stack-traces during printing exceptions; c48ba67854 2010-11-08 kinaba: it is not used for release builds.) 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: polemy/* 423f308350 2010-11-07 kinaba: main.d 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: All the other parts are written by Kazuhiro Inaba and 423f308350 2010-11-07 kinaba: licensed under NYSL 0.9982 ( http://www.kmonos.net/nysl/ ). 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: 423f308350 2010-11-07 kinaba: <<How to Use>> 423f308350 2010-11-07 kinaba: 9eec42eba1 2010-11-09 kinaba: > polemy 9eec42eba1 2010-11-09 kinaba: starts REPL 9eec42eba1 2010-11-09 kinaba: 9eec42eba1 2010-11-09 kinaba: > polemy foo.pmy 9eec42eba1 2010-11-09 kinaba: executes foo.pmy 9eec42eba1 2010-11-09 kinaba: 515502e8d1 2010-11-20 kinaba: > polemy -l foo.pmy 515502e8d1 2010-11-20 kinaba: after executing foo.pmy, starts REPL 3464a035ec 2010-11-20 kinaba: 3464a035ec 2010-11-20 kinaba: > polemy -l foo.pmy -l bar.pmy buz.pmy 3464a035ec 2010-11-20 kinaba: executes foo.pmy, bar.bmy, and then buz.pmy 9eec42eba1 2010-11-09 kinaba: 9eec42eba1 2010-11-09 kinaba: 9eec42eba1 2010-11-09 kinaba: 515502e8d1 2010-11-20 kinaba: <<Syntax>> 9eec42eba1 2010-11-09 kinaba: 515502e8d1 2010-11-20 kinaba: Comment is "# ... \n" 515502e8d1 2010-11-20 kinaba: 515502e8d1 2010-11-20 kinaba: E ::= 515502e8d1 2010-11-20 kinaba: // declaration 515502e8d1 2010-11-20 kinaba: | ("var"|"let"|"def"|LAYER) ID "=" E (";"|"in") E 515502e8d1 2010-11-20 kinaba: | ("var"|"let"|"def"|LAYER) ID "(" PARAMS ")" "{" E "}" (";"|"in") E 515502e8d1 2010-11-20 kinaba: | ("var"|"let"|"def"|LAYER) ID "=" E 515502e8d1 2010-11-20 kinaba: | ("var"|"let"|"def"|LAYER) ID "(" PARAMS ")" "{" E "}" 515502e8d1 2010-11-20 kinaba: // literal 515502e8d1 2010-11-20 kinaba: | INTEGER 515502e8d1 2010-11-20 kinaba: | STRING 515502e8d1 2010-11-20 kinaba: | "{" ENTRYS "}" 9eec42eba1 2010-11-09 kinaba: | "fun" "(" PARAMS ")" "{" E "}" 515502e8d1 2010-11-20 kinaba: // function call 515502e8d1 2010-11-20 kinaba: | E "(" ARGS")" 515502e8d1 2010-11-20 kinaba: where ARGS ::= E "," ... "," E 515502e8d1 2010-11-20 kinaba: PARAMS ::= ID LAYER* "," ... "," ID LAYER* 515502e8d1 2010-11-20 kinaba: ENTRYS ::= ID ":" E "," ... "," ID ":" E 515502e8d1 2010-11-20 kinaba: ID ::= 'a-zA-Z0-9_...'+ 515502e8d1 2010-11-20 kinaba: LAYER ::= "@" ID 515502e8d1 2010-11-20 kinaba: // operators 9eec42eba1 2010-11-09 kinaba: | "(" E ")" 515502e8d1 2010-11-20 kinaba: | E "." ID 515502e8d1 2010-11-20 kinaba: | E ".?" ID 9eec42eba1 2010-11-09 kinaba: | E BINOP E 9eec42eba1 2010-11-09 kinaba: | "if" "(" E ")" "{" E "}" 9eec42eba1 2010-11-09 kinaba: | "if" "(" E ")" "{" E "}" "else "{" E "}" 515502e8d1 2010-11-20 kinaba: // layered exec 515502e8d1 2010-11-20 kinaba: | LAYER "(" E ")" 515502e8d1 2010-11-20 kinaba: 515502e8d1 2010-11-20 kinaba: The following are actually rewritten to function calls: 515502e8d1 2010-11-20 kinaba: 515502e8d1 2010-11-20 kinaba: - if (E) then{E} else{E} ==> if( E, fun(){E}, fun(){E} ) 515502e8d1 2010-11-20 kinaba: - E BINOP E ==> BINOP(E, E) 515502e8d1 2010-11-20 kinaba: - E.ID ==> . (E, ID) 515502e8d1 2010-11-20 kinaba: - E.?ID ==> .?(E, ID) 515502e8d1 2010-11-20 kinaba: - {} ==> {}() 515502e8d1 2010-11-20 kinaba: - {ID:E, ...} ==> .=({...}, ID, E) 515502e8d1 2010-11-20 kinaba: 515502e8d1 2010-11-20 kinaba: Several styles of variable declaration can be used: 515502e8d1 2010-11-20 kinaba: 515502e8d1 2010-11-20 kinaba: - fun(x){ fun(y){x} } # K-combinator 515502e8d1 2010-11-20 kinaba: - fun(x){ let f = fun(y){x} in f } # let-in style 515502e8d1 2010-11-20 kinaba: - fun(x){ var f = fun(y){x}; f } # var-; style 515502e8d1 2010-11-20 kinaba: - fun(x){ def f = fun(y){x} in f } # you can use any combination of (let|var|def)-(;|in) 515502e8d1 2010-11-20 kinaba: - fun(x){ def f(y){x} in f } # syntax sugar for function declaration 515502e8d1 2010-11-20 kinaba: - fun(x){ let f(y){x}; f } # this is also ok 515502e8d1 2010-11-20 kinaba: - fun(x){ var f(y){x} } # omitting (;|in) returns the last declared object directly 515502e8d1 2010-11-20 kinaba: - fun(x,y){x} #< this is not equal to the above ones. functions are no curried. 515502e8d1 2010-11-20 kinaba: 515502e8d1 2010-11-20 kinaba: NOTE: Theres no "let rec" syntax, but still recursive definition works 515502e8d1 2010-11-20 kinaba: def f(x) { if(x==0){1}else{x*f(x-1)} } in f(10) #=> 3628800 515502e8d1 2010-11-20 kinaba: yet still the code below also works 515502e8d1 2010-11-20 kinaba: def x=21 in def x=x+x in x #=> 42. 515502e8d1 2010-11-20 kinaba: The internal scoping mechanism is a little tricky (this is for coping with 515502e8d1 2010-11-20 kinaba: the "layer" feature explained below), but I hope that it works as everyone 515502e8d1 2010-11-20 kinaba: expects in most cases, as long as you don't use the same-name-variables heavily :). 515502e8d1 2010-11-20 kinaba: 515502e8d1 2010-11-20 kinaba: 9eec42eba1 2010-11-09 kinaba: 515502e8d1 2010-11-20 kinaba: <<Basic Features>> 9eec42eba1 2010-11-09 kinaba: 515502e8d1 2010-11-20 kinaba: Polemy is an untyped functional programming language that has 515502e8d1 2010-11-20 kinaba: - integers: 0, 123, 456666666666666666666666666666666666666789, ... 515502e8d1 2010-11-20 kinaba: - strings: "hello, world!\n", ... 515502e8d1 2010-11-20 kinaba: - tables: {car: 1, cdr: {car: 2, cdr: {}}} 515502e8d1 2010-11-20 kinaba: - functions: fun(x){x+1} 515502e8d1 2010-11-20 kinaba: as primitive datatypes. Functions capture lexical closures. 515502e8d1 2010-11-20 kinaba: It is almost 'pure' (except the primitve function "print" and some 515502e8d1 2010-11-20 kinaba: trick inside scoping mechanisms). 515502e8d1 2010-11-20 kinaba: 9eec42eba1 2010-11-09 kinaba: 515502e8d1 2010-11-20 kinaba: <<Layer>> 9eec42eba1 2010-11-09 kinaba: 515502e8d1 2010-11-20 kinaba: to be written