Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the named-read-macros Reference Manual, version 1.0.0, generated automatically by Declt version 3.0 "Montgomery Scott" on Thu Mar 11 14:17:36 2021 GMT+0.
• Introduction | What named-read-macros is all about | |
• Systems | The systems documentation | |
• Files | The files documentation | |
• Packages | The packages documentation | |
• Definitions | The symbols documentation | |
• Indexes | Concepts, functions, variables and data types |
Copyright (c) 2017-2021 William Yao
Read macros are pretty handy when Lispy sexps just don't cut it. Unfortunately,
having to hunt around in the dispatch table or in the read macro table to
avoid read macro collisions doesn't leave a whole bunch of usable characters.
So instead, NAMED-READ-MACROS
lets you attach a read macro to any symbol,
and call it like any other function or macro.
(named-readtables:in-readtable named-read-macros:readtable)
(named-read-macros:define escapify
(with-output-to-string (output)
(loop for char = (read-char *standard-input* nil nil t)
while char
do (write-char char output))))
(escapify
Any characters I put in here will be put into the output string, even
things that would normally require escapes, like backslashes!
\ \ \ \
end-escapify)
=> "Any characters I put in here will be put into the output string, even
things that would normally require escapes, like backslashes!
\\ \\ \\ \\"
You can hijack the Lisp reader without having to carefully avoid read macro
conflicts! And since NAMED-READ-MACROS
attaches read macros to symbols, you
don't have to fuss about with readtables either, and you can export and import
read macros the same way you do with functions and macros and all the other
symbol-based stuff.
For any file which needs to use your named read macros, make sure to either
switch your readtable to NAMED-READ-MACROS:READTABLE
, or fuse a read table
you're using with NAMED-READ-MACROS:READTABLE-MIXIN
.
READTABLE
Contains the standard readtable, but with the macro character for #\(
rewritten to check for a named read macro in the head position.
READTABLE-MIXIN
Just contains the rewritten macro for #\(
.
Then define a named read macro with NAMED-READ-MACROS:DEFINE
.
DEFINE NAME &BODY BODY
Creates a named read macro, which executes BODY
in a context where
*STANDARD-INPUT*
is bound to a stream containing just the contents which
the read macro was called with, and associates this macro with NAME
.
Just like a normal macro, BODY
should return a Lisp form to then get
evaluated where the named read macro was called.
Because NAMED-READ-MACROS
hijacks the Lisp reader, we can't rely on matching
parentheses to know when the newly-defined read macro ends, so we look for
the sequence of characters "END-${NAME}"
, immediately followed by a close
parenthesis, in order to know when the read macro ends. Case is checked
against NAME
by transforming the ending string according to the case of the
current readtable; if (SYMBOL-NAME NAME)
matches the transformed ending
string exactly, we've found the end tag. In particular, this means that using
DEFINE
with a pipe-enclosed symbol with lowercase characters will make such
a read macro impossible to end under the standard readtable (though why one
would define such a macro is another question entirely!)
Leading whitespace after opening the read macro will not be passed to BODY
,
but trailing whitespace before the ending tag will.
Note that DEFINE
has no compile-time effects by default; the rationale
is that doing so would also require any functions used by a read macro
defined by DEFINE
to be available at compile-time. Since this is not the
usual, DEFINE
explicitly has no compile-time effects to avoid this problem.
If you want a named read macro to be available at compile-time, wrap DEFINE
and any necessary functions in an explicit EVAL-WHEN
.
An interesting usage would be to write an LALR(1) parser generator for Common Lisp, but instead of generating a function or a standalone executable, it instead generates read macros. Any parsers generated could then be embedded directly within Lisp code, allowing for very complex read macros to be easily written, and compile directly to Lisp forms.
Another use would be something like Perl's __DATA__
directive, embedding
files and data directly in Lisp code.
Next: Files, Previous: Introduction, Up: Top [Contents][Index]
The main system appears first, followed by any subsystem dependency.
• The named-read-macros system |
William Yao <williamyaoh@gmail.com>
William Yao <williamyaoh@gmail.com>
BSD-3
Make read macros more Lispy. Attach read macros to symbols.
Provide a definition facility to define read macros and attach them to symbols, avoiding the possibility of collisions in readtable characters.
1.0.0
named-readtables
named-read-macros.asd (file)
Files are sorted by type and then listed depth-first from the systems components trees.
• Lisp files |
• The named-read-macros.asd file | ||
• The named-read-macros/packages.lisp file | ||
• The named-read-macros/named-read-macros.lisp file | ||
• The named-read-macros/readtables.lisp file |
Next: The named-read-macros/packages․lisp file, Previous: Lisp files, Up: Lisp files [Contents][Index]
named-read-macros.asd
named-read-macros (system)
Next: The named-read-macros/named-read-macros․lisp file, Previous: The named-read-macros․asd file, Up: Lisp files [Contents][Index]
named-read-macros (system)
packages.lisp
Next: The named-read-macros/readtables․lisp file, Previous: The named-read-macros/packages․lisp file, Up: Lisp files [Contents][Index]
packages.lisp (file)
named-read-macros (system)
named-read-macros.lisp
Previous: The named-read-macros/named-read-macros․lisp file, Up: Lisp files [Contents][Index]
named-read-macros.lisp (file)
named-read-macros (system)
readtables.lisp
Next: Definitions, Previous: Files, Up: Top [Contents][Index]
Packages are listed by definition order.
• The named-read-macros package |
packages.lisp (file)
common-lisp
Definitions are sorted by export status, category, package, and then by lexicographic order.
• Exported definitions | ||
• Internal definitions |
Next: Internal definitions, Previous: Definitions, Up: Definitions [Contents][Index]
• Exported macros | ||
• Exported generic functions | ||
• Exported conditions |
Next: Exported generic functions, Previous: Exported definitions, Up: Exported definitions [Contents][Index]
Creates a named read macro, which executes ‘BODY‘ in a context where
‘*STANDARD-INPUT*‘ is bound to a stream containing just the contents which
the read macro was called with, and associates this macro with ‘NAME‘.
Just like a normal macro, ‘BODY‘ should return a Lisp form to then get
evaluated where the named read macro was called.
Because ‘NAMED-READ-MACROS‘ hijacks the Lisp reader, we can’t rely on
matching parentheses to know when the newly-defined read macro *ends*, so we
look for the sequence of characters ‘’END-${NAME}’‘, *immediately* followed
by a close parenthesis, in order to know when the read macro ends. Case is
checked against ‘NAME‘ by transforming the ending string according to the
case of the current readtable; if ‘(SYMBOL-NAME NAME)‘ matches the
transformed ending string exactly, we’ve found the end tag. In particular,
this means that using ‘DEFINE‘ with a pipe-enclosed symbol with lowercase
characters will make such a read macro impossible to end under the standard
readtable (though why one would define such a macro is another question
entirely!)
Leading whitespace after opening the read macro will not be passed to ‘BODY‘,
but trailing whitespace before the ending tag will.
Note that ‘DEFINE‘ has no compile-time effects by default; the rationale is that doing so would also require any functions used by a read macro defined by ‘DEFINE‘ to be available at compile-time. Since this is not the usual, ‘DEFINE‘ explicitly has no compile-time effects to avoid this problem. If you want a named read macro to be available at compile-time, wrap ‘DEFINE‘ and any necessary functions in an explicit ‘EVAL-WHEN‘.
named-read-macros.lisp (file)
Next: Exported conditions, Previous: Exported macros, Up: Exported definitions [Contents][Index]
named-read-macros.lisp (file)
named-read-macros.lisp (file)
Previous: Exported generic functions, Up: Exported definitions [Contents][Index]
named-read-macros.lisp (file)
style-warning (condition)
:name
read-macro-redefinition-warning-name (generic function)
:prev-type
read-macro-redefinition-warning-prev-type (generic function)
Previous: Exported definitions, Up: Definitions [Contents][Index]
• Internal functions |
Previous: Internal definitions, Up: Internal definitions [Contents][Index]
named-read-macros.lisp (file)
named-read-macros.lisp (file)
named-read-macros.lisp (file)
Return a function which will transform any string per the given readtable’s case-sensitivity.
named-read-macros.lisp (file)
Previous: Definitions, Up: Top [Contents][Index]
• Concept index | ||
• Function index | ||
• Variable index | ||
• Data type index |
Next: Function index, Previous: Indexes, Up: Indexes [Contents][Index]
Jump to: | F L N |
---|
Jump to: | F L N |
---|
Next: Variable index, Previous: Concept index, Up: Indexes [Contents][Index]
Jump to: | C D F G M R |
---|
Jump to: | C D F G M R |
---|
Next: Data type index, Previous: Function index, Up: Indexes [Contents][Index]
Jump to: | N P S |
---|
Index Entry | Section | ||
---|---|---|---|
| |||
N | |||
name : | Exported conditions | ||
| |||
P | |||
prev-type : | Exported conditions | ||
| |||
S | |||
Slot, name : | Exported conditions | ||
Slot, prev-type : | Exported conditions | ||
|
Jump to: | N P S |
---|
Previous: Variable index, Up: Indexes [Contents][Index]
Jump to: | C N P R S |
---|
Jump to: | C N P R S |
---|