Skip to content

Instantly share code, notes, and snippets.

@andlys
Created September 12, 2017 06:08
Show Gist options
  • Save andlys/70f563da69c964721194ad2cdf36fba9 to your computer and use it in GitHub Desktop.
Save andlys/70f563da69c964721194ad2cdf36fba9 to your computer and use it in GitHub Desktop.
(defmacro nth-expr (n &rest args)
(let ((g (gensym)))
`(let ((,g (1- ,n)))
(eval (nth ,g ',args))))) ; TODO: make this work without eval function
(defun watch () (print 'evaluated!))
(let ((n 2))
(macroexpand-1 '(nth-expr n (watch) (+ 1 3) 'value)))
(let ((n 2))
(nth-expr n (watch) (+ 1 3) 'value))
; => 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment