Skip to content

Instantly share code, notes, and snippets.

@Bronsa
Last active June 4, 2019 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bronsa/fa02d5bdebccba36c709683406dac0f7 to your computer and use it in GitHub Desktop.
Save Bronsa/fa02d5bdebccba36c709683406dac0f7 to your computer and use it in GitHub Desktop.
(defun gensymify (body &optional (mappings (make-hash-table :test #'equal)))
(mapcar
(lambda (el)
(cond
((listp el)
(gensymify el mappings))
((and (symbolp el)
(not (symbol-package el)))
(let* ((n (symbol-name el))
(s (gethash n mappings)))
(or s (let* ((g (gensym)))
(setf (gethash n mappings) g)
g))))
(t el)))
body))
(set-dispatch-macro-character #\# #\`
(lambda (stream char n)
(declare (ignore char n))
(let ((body (list (quote quote) (read stream t nil t))))
(gensymify body))))
(eval #`(let ((#:a 1)) #:a)) ;; => 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment