Advertisement
Guest User

Gensym in macros

a guest
Mar 1st, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.60 KB | None | 0 0
  1. (defmacro with-list-iterator ((name list-form) &body body)
  2.   (let ((var (gensym)))
  3.     `(let ((,var ,list-form))
  4.        (symbol-macrolet ((,name (pop ,var)))
  5.          ,@body))))
  6.  
  7. (defmacro with-list-iterator2 ((name list-form) &body body)
  8.   (let ((var '#:x))
  9.     `(let ((,var ,list-form))
  10.        (symbol-macrolet ((,name (pop ,var)))
  11.          ,@body))))
  12.  
  13. (with-list-iterator (hello '(a b c))
  14.   (with-list-iterator (hi '(d e f))
  15.     (list (list hello hi) (list hello hi) )))
  16.  
  17. (with-list-iterator2 (hello '(a b c))
  18.   (with-list-iterator2 (hi '(d e f))
  19.     (list (list hello hi) (list hello hi) )))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement