code cleanup

This commit is contained in:
Danny Yoo 2011-02-21 21:43:42 -05:00
parent 95a3168659
commit 3b15c46dec
3 changed files with 46 additions and 11 deletions

View File

@ -7,6 +7,11 @@
"package.rkt")
;; A hacky way to test the evaluation.
;;
;; TODO: figure out how to do this without so many urls. Push-style from the server
;; should be able to work.
(provide evaluate)
(define port (+ 8000 (random 8000)))

View File

@ -7,7 +7,16 @@
// function closures are Closures
// primitive procedures are regular functions.
// No error trapping at the moment.
var Primitives = {
'display': function(argl) {
MACHINE.params.currentDisplayer(argl[0]);
},
'newline': function(argl) {
MACHINE.params.currentDisplayer("\n");
},
'=': function(argl) {
return argl[0] === argl[1][0];
},
@ -27,11 +36,21 @@ var Primitives = {
'/': function(argl) {
return argl[0] / argl[1][0];
},
'display': function(argl) {
MACHINE.params.currentDisplayer(argl[0]);
'cons': function(argl) {
return [argl[0], argl[1][0]];
},
'newline': function(argl) {
MACHINE.params.currentDisplayer("\n");
'list': function(argl) {
return argl;
},
'car': function(argl) {
return argl[0][0];
},
'cdr': function(argl) {
return argl[0][1];
},
'null?': function(argl) {
return argl[0] === undefined;
}
};

View File

@ -7,10 +7,14 @@
[(_ s exp)
(with-syntax ([stx stx])
(syntax/loc #'stx
(let-values ([(output time) (evaluate s)])
(unless (string=? output exp)
(raise-syntax-error #f (format "Expected ~s, got ~s" exp output)
#'stx)))))]))
(begin
(printf "running test...")
(let-values ([(output time) (evaluate s)])
(unless (string=? output exp)
(printf " error!\n")
(raise-syntax-error #f (format "Expected ~s, got ~s" exp output)
#'stx)))
(printf " ok\n"))))]))
(test '(begin (define (f x)
@ -24,6 +28,13 @@
(display (f 10000)))
"6\n10\n50005000")
"ok"
(test '(begin (define (length l)
(if (null? l)
0
(+ 1 (length (cdr l)))))
(display (length (list 1 2 3 4 5 6)))
(newline)
(display (length (list "hello" "world")))
(newline))
"6\n2\n")