A cute reader hack



For those who like to program in a functional style without having to
type FUNCALL all the time:

(defun \_-reader (stream char)
(declare (ignore char))
`(lambda (&rest #1=#.(gensym "ARGS")) (apply ,(read stream) #1#)))

(set-macro-character #\_ '\_-reader t)

Now you can call the local version of a function simply by preceding its
name with an underscore. (The cost is that you lose the ability to have
variables and functions whose names begin with underscore. If you don't
like that you can choose a different character, or use a dispatching
macro character.)

e.g.:

(defun foo (list)
(list 1 (_list 2))) ; Instead of (list 1 (funcall list 2))

(foo #'vector) --> (1 #(2))

rg
.



Relevant Pages