From: Raimon Grau Date: Fri, 14 Dec 2012 22:37:46 +0000 (+0100) Subject: while first approach X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=894164decccd2dc2e2a58d0b9fa0dd2a839b609c;p=jscl.git while first approach --- diff --git a/lispstrack.lisp b/lispstrack.lisp index 4baeb39..0057c2e 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -28,7 +28,6 @@ separator (join (cdr list) separator))))) - ;;; Compiler (defvar *compilations* nil) @@ -78,6 +77,11 @@ body can access to the local environment through the variable env" (define-compilation quote (sexp) (lisp->js sexp)) +(define-compilation while (pred &rest body) + (format nil "(function(){while(~a){~{~a~}}})()" + (ls-compile pred env) + (mapcar (lambda (x) (ls-compile x env)) body))) + (defparameter *env* '()) (defparameter *env-fun* '()) @@ -94,11 +98,14 @@ body can access to the local environment through the variable env" ;; funcall ))))) -(defun ls-compile-block (sexps env) +(defun ls-compile-sexps (sexps env) (concat (join (mapcar (lambda (x) (ls-compile x env)) - (butlast sexps)) + sexps) "; -") +"))) + +(defun ls-compile-block (sexps env) + (concat (ls-compile-sexps (butlast sexps env) env) "; return " (ls-compile (car (last sexps)) env) ";"))