Commits

Shlomi Fish committed 9f828aa

Add the (while) macro.

Comments (0)

Files changed (2)

lurking-lisp-library/lurking.lisp

   (apply 'concatenate 'string lst))
 
 (op2assign ~)
+
+;;; Taken from http://p-cos.blogspot.com/2007/02/what-is-point-of-macros.html
+;;; Thanks!
+(defmacro while (expression &body body)
+  `(tagbody
+     start (if (not ,expression) (go end))
+           ,@body
+           (go start)
+     end))

lurking-lisp-library/t/op-equal-sign.lisp

 
 (let ((producer (make-instance 'tap-producer)))
   (init-test producer)
-  (emit-plan producer :plan-argument 7) ; simple plan, three tests planned
+  (emit-plan producer :plan-argument 9) ; simple plan, three tests planned
   (let ((result 28))
     (-= result 4)
     ; TEST
     (emit-result producer :success (equal string1 "HelloWorld")
                  :description "Testing ~="))
 
+  ; Let's test the (while ) macro.
+  (let ((x 1) (cnt 0))
+    (while (< x 10)
+           (*= x 2)
+           (+= cnt 1))
+    ; TEST
+    (emit-result producer :sucesss (= x 16)
+                 :description "while loop works (1)")
+    ; TEST
+    (emit-result producer :success (= cnt 4)
+                 :description "while loop works (2)"))
+
   (finalize-test producer))