Skip to content

Instantly share code, notes, and snippets.

@ijp
Created February 16, 2012 22:39
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 ijp/1848438 to your computer and use it in GitHub Desktop.
Save ijp/1848438 to your computer and use it in GitHub Desktop.
;; instead of (cut foo bar <> baz <>)
;; you can do #[foo bar _ baz _]a
(read-hash-extend #\[
(lambda (char port)
(let loop ((terms '()) (gensyms '()))
(let ((c (peek-char port)))
(cond ((eof-object? c)
(error 'wtf?))
((char-whitespace? c)
(read-char port)
(loop terms gensyms))
((char=? #\] c)
(read-char port)
`(lambda ,(reverse gensyms) ,(reverse terms)))
((char=? #\_ c)
(read-char port)
(let ((next (peek-char port)))
(cond ((or (char-whitespace? next)
(char=? #\] next))
(let ((g (gensym "_")))
(loop (cons g terms) (cons g gensyms))))
(else
(unread-char #\_ port)
(loop (cons (read port) terms) gensyms)))))
(else
(loop (cons (read port) terms) gensyms)))))))
@ijp
Copy link
Author

ijp commented Feb 17, 2012

If you want to use this in emacs with paredit, I recommend you

(add-to-list 'paredit-space-for-delimiter-predicates
                (lambda (endp delimiter)
                  (not (eql delimiter ?#))))

to your .emacs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment