Skip to content

Commit

Permalink
Improvements around REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
afeinberg committed Dec 11, 2011
1 parent 9117230 commit e4e0312
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions builtins.ml
Expand Up @@ -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."
18 changes: 9 additions & 9 deletions main.ml
Expand Up @@ -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
Expand All @@ -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.