Artifact Content
Not logged in

Artifact b45d599d08f18ee090e56aa62009f1b4dbad6c56


     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  
    54  
    55  <<Syntax>>
    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
    63       | ("var"|"let"|"def"|LAYER) ID "=" E
    64       | ("var"|"let"|"def"|LAYER) ID "(" PARAMS ")" "{" E "}"
    65     // literal
    66       | INTEGER
    67  	 | STRING
    68  	 | "{" ENTRYS "}"
    69       | "fun" "(" PARAMS ")" "{" E "}"
    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
    78       | "(" E ")"
    79  	 | E "." ID
    80  	 | E ".?" ID
    81       | E BINOP E
    82       | "if" "(" E ")" "{" E "}"
    83       | "if" "(" E ")" "{" E "}" "else "{" 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  
   116  
   117  <<Basic Features>>
   118  
   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  
   128  
   129  <<Layer>>
   130  
   131   to be written