(* * This module does some simple exercising of the lispVal abstract type. * * Requires lispvalX.ml, where X is the latest version number. *) structure LispValTests = struct fun isGoodbye(result) = eq(result, #2(sread1(sstream("(bye)")))) orelse (lnull(result) andalso end_of_stream(std_in)) fun read_print_loop() = while true do ( print("MLX>"); flush_out(std_out); let exception LispDone; val result = read() in princ(result); print("\n"); flush_out(std_out); if isGoodbye(result) then ( print("Bye.\n"); raise LispDone ) else ( print("\n"); flush_out(std_out) ) end handle MissingDoubleQuote => print("Missing double quote.\n\n") | TooManyRightParens => print("Too many right parens.\n\n") | TooFewRightParens => print("Too few right parens.\n\n") ) fun tests() = let val l = hd(sread("( 10 20 x \"hi there\" t y (30 40 50 (60 70)) nil 80 )")) in ( saneprint(car(l)); saneprint(cdr(l)); eq(cons(car(l), cdr(l)), l); saneprint(car(cdr(car(cdr(cdr(cdr(car(cdr(cdr(cdr(cdr(cdr(cdr(l )))))))))))))); saneprint(hd(tl(sread("''a '(a b ''''c)")))); print("\n\nYou're now entering the read-print loop. Enjoy\n"); read_print_loop() handle LispDone => print("\n") ) end end open LispValTests;