From 640c35895966eed3b3a9c838ed76fed774a5b5b8 Mon Sep 17 00:00:00 2001 From: Raimon Grau Date: Fri, 14 Dec 2012 23:48:09 +0100 Subject: [PATCH] while --- lispstrack.lisp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lispstrack.lisp b/lispstrack.lisp index 0057c2e..d7e41a1 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -32,6 +32,19 @@ (defvar *compilations* nil) +(defun ls-compile-sexps (sexps env) + (concat (join (mapcar (lambda (x) + (ls-compile x env)) + sexps) + "; +"))) + +(defun ls-compile-block (sexps env) + (concat (ls-compile-sexps (butlast sexps env) env) + "; +return " (ls-compile (car (last sexps)) env) ";")) + + (defun extend-env (args env) (append (mapcar #'make-binding args) env)) @@ -78,9 +91,9 @@ body can access to the local environment through the variable env" (lisp->js sexp)) (define-compilation while (pred &rest body) - (format nil "(function(){while(~a){~{~a~}}})()" + (format nil "(function(){while(~a){~a}})() " (ls-compile pred env) - (mapcar (lambda (x) (ls-compile x env)) body))) + (ls-compile-sexps body env))) (defparameter *env* '()) (defparameter *env-fun* '()) @@ -97,15 +110,3 @@ body can access to the local environment through the variable env" (apply compiler-func env (cdr sexp)) ;; funcall ))))) - -(defun ls-compile-sexps (sexps env) - (concat (join (mapcar (lambda (x) - (ls-compile x env)) - sexps) - "; -"))) - -(defun ls-compile-block (sexps env) - (concat (ls-compile-sexps (butlast sexps env) env) - "; -return " (ls-compile (car (last sexps)) env) ";")) -- 1.7.10.4