Permalink
Browse files

Improvements around REPL

  • Loading branch information...
afeinberg committed Dec 11, 2011
1 parent 9117230 commit e4e0312e71634401e92a887deb3230c5eaf6fe35
Showing with 15 additions and 15 deletions.
  1. +6 −6 builtins.ml
  2. +9 −9 main.ml
View
@@ -133,24 +133,24 @@ let rec lisp_print sexp =
Null -> ()
| Cons (_) ->
begin
- Printf.printf "(" ;
+ print_string "(" ;
lisp_print (car sexp) ;
let rec loop s =
match s with
Cons (_) ->
- Printf.printf " " ;
+ print_string " " ;
lisp_print (car s) ;
loop (cdr s)
| _ -> ()
in
loop (cdr sexp) ;
- Printf.printf ")" ;
+ print_string ")" ;
end
| Atom (n) ->
- Printf.printf "%s" n
+ print_string n
| Lambda (largs, lsexp) ->
- Printf.printf "#" ;
+ print_string "#" ;
lisp_print largs ;
lisp_print lsexp
| _ ->
- Printf.printf "Error."
+ print_string "Error."
View
18 main.ml
@@ -5,8 +5,6 @@ open Sexp
let lisp_read inp =
let lexbuf = Lexing.from_channel inp in
Parser.main Lexer.token lexbuf
-
-
let init_env () =
let env = Symtab.create 32 in
@@ -31,12 +29,14 @@ let _ =
let chin = stdin
in
while true do
- (try
- Printf.printf "> " ;
- lisp_print (eval (lisp_read chin) env)
- with
- Parsing.Parse_error -> Printf.printf "Parser error"
- | Lexer.Eof -> exit 0);
- Printf.printf "\n"
+ try
+ print_string "> " ;
+ flush stdout ;
+ let sexp_eval = eval (lisp_read chin) env in
+ lisp_print sexp_eval ;
+ print_newline () ;
+ with
+ Parsing.Parse_error -> print_endline "Parse error"
+ | Lexer.Eof -> exit 0
done

0 comments on commit e4e0312

Please sign in to comment.