Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
;Macro study
(defun range-helper(x)
(if (= x 0)
(list x)
(cons x (range-helper (- x 1)))
(defun range (x)
(reverse (range-helper (- x 1)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;stupid way
(defvar ans nil)
(loop for x in (range 10) if (= 0 (mod x 2)) do
(setq ans (append ans (list x)))
(print ans)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wise way
(defmacro lcomp (expression for var in list conditional condition-test)
(let ((result (gensym)))
`(let ((,result nil))
(loop for ,var in ,list
do (setq ,result (append ,result (list ,expression))))
(setq ans2 (lcomp (+ (* x x) 10) for x in (range 10) if (= 0 (mod x 2))))
(print ans2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment