1 ! Copyright (C) 2015 Jordan Lewis.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs combinators combinators.short-circuit
4 continuations fry io kernel math lib.printer lib.reader lib.types
5 quotations readline sequences ;
17 : eval-symbol ( sym env -- ast )
18 [ name>> ] dip ?at [ "no variable " prepend throw ] unless ;
20 : eval-list ( list env -- ast )
23 : eval-assoc ( assoc env -- ast )
24 '[ [ _ EVAL ] bi@ ] assoc-map ;
26 : eval-ast ( ast env -- ast )
28 { [ over malsymbol? ] [ eval-symbol ] }
29 { [ over sequence? ] [ eval-list ] }
30 { [ over assoc? ] [ eval-assoc ] }
34 : READ ( str -- maltype ) read-str ;
36 : EVAL ( maltype env -- maltype )
37 eval-ast dup { [ array? ] [ empty? not ] } 1&& [
39 dup quotation? [ "not a fn" throw ] unless
43 : PRINT ( maltype -- str ) pr-str ;
47 READ repl-env EVAL PRINT
49 nip pr-str "Error: " swap append
55 [ REP print flush ] unless-empty