Skip to content

Instantly share code, notes, and snippets.

@youz
Forked from snmsts/shecomma.lisp
Last active July 6, 2017 07:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youz/6b3604e524c1636a03e1a3444158ea20 to your computer and use it in GitHub Desktop.
Save youz/6b3604e524c1636a03e1a3444158ea20 to your computer and use it in GitHub Desktop.
#,
(defun shecomma-reader (stream sub-character n)
(declare (ignore sub-character))
(let ((a (gensym "A"))
(f (read stream nil nil)))
`(lambda (&rest ,a)
(apply ,(case n
(0 `(quote ,f))
(1 f)
(t `(function ,f)))
,a))))
(set-dispatch-macro-character #\# #\, #'shecomma-reader)
(defun f (n) (/ n 4))
(flet ((f (x) (* 2 x)))
(let ((f (lambda (x) (* 3 x))))
(values (#,f 1) (#0,f 1) (#1,f 1) (#2,f 1))))
;; -> 2, 1/4, 3, 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment