:read-macros is a library of useful read macros for CL.
It includes
Setup can be as simple as (load "read-macros.lisp") or (asdf:operate 'asdf:load-op :read-macros).
By default, this package sets #?
to call read-macros:dispatch. This can be suppressed by setting the feature :delay-read-macros-install before loading the package.
; Example: use #_ instead of #?
(pushnew :delay-read-macros-install *features*)
(load "read-macros")
(read-macros:install #\_)
(setf *features*
(remove :delay-read-macros-install *features*))
Here is a quick overview of the included macros. For working code, see examples.lisp
. For more details, see the docstrings and #| comments |#
in read-macros.lisp
.
;; conditional reads
#?(read-if (= 1 2) :true :false) ; :false
#?(read-when (= 1 2) :true) ; (values)
#?(read-unless (= 1 2) :false) ; :false
#?(read-cond
(= 1 2) :a
(= 1 3) :b
t :c) ; :c
;; conditional reads based on *features*
#?(read-if-feature (or sbcl (not sbcl)) :true :false) ; :true
#?(read-when-feature (and) :true) ; :true
#?(read-unless-feature #.(cl:car cl:*features*) :true) ; (values)
#?(read-cond-features
(gensym) :a
(not (and)) :b) ; (values)
;; conditional block reads
#?(read-block-if nil)
1 ; (values)
#?(read-block-else-if t)
2 ; 2
#?(read-block-else)
3 ; (values) -- previous test passed
#?(read-block-end)
;; lexical read manipulation
#?(read-let ((*read-base* 3)) 20) ; 6=2*3
;; here documents
#?(read-here _EOF) The rest of this line is ignored.
#?(read-here) reads (text) until _EOF.
_EOF
; "#?(read-here) reads (text) until _EOF."
cl-syntax-sugar provides another set of useful reader macros.
EDITOR-HINTS (docs) contains facilities for naming and manipulating readtables.
Copyright (c) 2008 Daniel Herring.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
The author may be contacted at dherring@at.tentpost.dot.com