Created
February 16, 2012 22:39
-
-
Save ijp/1848438 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to use this in emacs with paredit, I recommend you
to your .emacs