Commits

Shlomi Fish committed 54b5ac8

Add the (with) macro.

Comments (0)

Files changed (2)

lurking-lisp-library/lurking.lisp

            ,@body
            (go start)
      end))
+
+;;; A small helper function for the with macro.
+;;; Converts a flat list to a list of two element lists.
+(defun withify (lst)
+  (if (null lst) 
+    ()
+    (cons (list (car lst) (cadr lst)) (withify (cddr lst)))))
+
+;;; (with (var1 value1 var2 value2 var3 value3 ...) macro inspired by Arc.
+(defmacro with (vars &body body)
+  `(let* ,(withify vars) ,@body))
+

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

 
 (let ((producer (make-instance 'tap-producer)))
   (init-test producer)
-  (emit-plan producer :plan-argument 9) ; simple plan, three tests planned
+  (emit-plan producer :plan-argument 12)
   (let ((result 28))
     (-= result 4)
     ; TEST
     (emit-result producer :success (= cnt 4)
                  :description "while loop works (2)"))
 
+  ; Let's test the (with ) macro.
+  (with (v5 5 v10 10 v8 8)
+
+        ; TEST
+        (emit-result producer :success (= v5 5)
+                     :description "with - v5 is 5")
+
+        ; TEST
+        (emit-result producer :success (= v8 8)
+                     :description "with - v8 is 8")
+
+        ; TEST
+        (emit-result producer :success (= v10 10)
+                     :description "with - v10 is 10"))
+
   (finalize-test producer))