sharp-back syntax



I hate having to type l-a-m-b-d-a over and over again...

luckily it's easy to add syntax to Lisp:

(defun sharp-back-var-p (x)
(when (symbolp x)
(let ((n (symbol-name x)))
(when (> (length n) 0)
(char= (char n 0)
#\?)))))

(defun sharp-back-expand (form)
(let (vs)
(labels ((rfn (x)
(if (sharp-back-var-p x)
(pushnew x vs)
(when (listp x)
(mapc #'rfn x)))))
(rfn form)
`(lambda ,(nreverse vs) ,form))))

(set-dispatch-macro-character #\# #\`
#'(lambda (s c1 c2)
(declare (ignore c1 c2))
(sharp-back-expand (read s))))


usage:

#`(> 4 5) => (lambda () (> 4 5))
#`(= ?x 5) => (lambda (?x) (= ?x 5))
#`(print (+ ?a ?b)) => (lambda (?a ?b) (print (+ ?a ?b)))
#`(list ?x ?y ?x ?x ?y) => (lambda (?x ?y) (list ?x ?y ?x ?x ?y)
(mapcar #`(> ?x ?y) list1 list2) => (mapcar (lambda (?x ?y) (> ?x ?y))
list1 list2)

hth

Nick

.