From 894164decccd2dc2e2a58d0b9fa0dd2a839b609c Mon Sep 17 00:00:00 2001 From: Raimon Grau Date: Fri, 14 Dec 2012 23:37:46 +0100 Subject: [PATCH] while first approach --- lispstrack.lisp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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) ";")) -- 1.7.10.4