Add expansion for defmacro! macros.
This commit is contained in:
parent
32a4e9b9bd
commit
ca7fb58b38
|
@ -226,8 +226,8 @@ some code should be executed based on the results of those bindings.
|
||||||
These macros abstract common operations on files.
|
These macros abstract common operations on files.
|
||||||
|
|
||||||
@cl:with-package[name="kutils"](
|
@cl:with-package[name="kutils"](
|
||||||
@cl:doc(macro read-file-string)
|
@cl:doc(macro! read-file-as-string)
|
||||||
@cl:doc(macro with-string-output-to-file)
|
@cl:doc(macro! with-string-output-to-file)
|
||||||
@cl:doc(macro with-read-from-file)
|
@cl:doc(macro with-read-from-file)
|
||||||
@cl:doc(macro with-write-to-file)
|
@cl:doc(macro with-write-to-file)
|
||||||
)
|
)
|
||||||
|
@ -342,7 +342,7 @@ described in "Miscellaneous utilities" under "Vector-related".)
|
||||||
@item(@c(partial) is a function defined in @c(kutils.lisp), described
|
@item(@c(partial) is a function defined in @c(kutils.lisp), described
|
||||||
in "Miscellaneous utilities" under "Clojure-inspired functions".)
|
in "Miscellaneous utilities" under "Clojure-inspired functions".)
|
||||||
|
|
||||||
@item(@c(read-file-string) is a macro defined in @c(macros.lisp),
|
@item(@c(read-file-as-string) is a macro defined in @c(macros.lisp),
|
||||||
described in "Macros" under "File macros".)
|
described in "Macros" under "File macros".)
|
||||||
|
|
||||||
@item(@c(sethash) is a macro defined in @c(kutils-hash-tables.lisp),
|
@item(@c(sethash) is a macro defined in @c(kutils-hash-tables.lisp),
|
||||||
|
@ -422,7 +422,7 @@ Alphabetical documentation for all exported symbols.
|
||||||
@cl:doc(function new-hash-table)
|
@cl:doc(function new-hash-table)
|
||||||
@cl:doc(function new-vector)
|
@cl:doc(function new-vector)
|
||||||
@cl:doc(function partial)
|
@cl:doc(function partial)
|
||||||
@cl:doc(macro read-file-string)
|
@cl:doc(macro! read-file-as-string)
|
||||||
@cl:doc(macro sethash)
|
@cl:doc(macro sethash)
|
||||||
@cl:doc(function symb)
|
@cl:doc(function symb)
|
||||||
@cl:doc(function take)
|
@cl:doc(function take)
|
||||||
|
@ -432,7 +432,7 @@ Alphabetical documentation for all exported symbols.
|
||||||
@cl:doc(macro whenlet*)
|
@cl:doc(macro whenlet*)
|
||||||
@cl:doc(macro with-new-hash-table)
|
@cl:doc(macro with-new-hash-table)
|
||||||
@cl:doc(macro with-read-from-file)
|
@cl:doc(macro with-read-from-file)
|
||||||
@cl:doc(macro with-string-output-to-file)
|
@cl:doc(macro! with-string-output-to-file)
|
||||||
@cl:doc(macro with-write-to-file)
|
@cl:doc(macro with-write-to-file)
|
||||||
@cl:doc(function zip))
|
@cl:doc(function zip))
|
||||||
|
|
||||||
|
|
18
macros.lisp
18
macros.lisp
|
@ -92,25 +92,23 @@ resulting string to @c(path). Any remaining arguments are sent to
|
||||||
(let ((o!out (mkstr ,@body)))
|
(let ((o!out (mkstr ,@body)))
|
||||||
(princ o!out g!s)))))
|
(princ o!out g!s)))))
|
||||||
|
|
||||||
(defmacro with-read-from-file (path &rest args &key (direction nil directionp)
|
(defmacro with-read-from-file ((stream path &rest args &key (direction :input directionp)
|
||||||
&allow-other-keys)
|
&allow-other-keys)
|
||||||
"Read the form contained in @c(path), with any remaining arguments
|
&body body)
|
||||||
passed to @c(with-open-file)."
|
"Open @c(path) for reading, bound to @c(stream), with any remaining arguments
|
||||||
(let ((s (gensym)))
|
passed to @c(with-open-file), and execute @c(body)."
|
||||||
(declare (ignore direction))
|
|
||||||
(when directionp
|
(when directionp
|
||||||
(error "Specifying :direction is not allowed with READ-FILE."))
|
(error "Specifying :direction is not allowed with READ-FILE."))
|
||||||
`(with-open-file (,s ,path ,@args)
|
`(with-open-file (,stream ,path :direction ,direction ,@args)
|
||||||
(with-standard-io-syntax
|
,@body))
|
||||||
(read ,s)))))
|
|
||||||
|
|
||||||
(defmacro with-write-to-file ((stream path &rest args
|
(defmacro with-write-to-file ((stream path &rest args
|
||||||
&key (direction :output directionp)
|
&key (direction :output directionp)
|
||||||
&allow-other-keys)
|
&allow-other-keys)
|
||||||
&body body)
|
&body body)
|
||||||
"Evaluate @c(body) with the file at @c(path) opened and bound to the
|
"Evaluate @c(body) with the file at @c(path) opened and bound to the
|
||||||
value of @c(stream). Any remaining keyword arguments are passed to
|
value of @c(stream). Any remaining keyword arguments are passed to
|
||||||
@c(with-open-file)."
|
@c(with-open-file)."
|
||||||
(when directionp
|
(when directionp
|
||||||
(error "Specifying :direction is not allowed with WRITE-FILE."))
|
(error "Specifying :direction is not allowed with WRITE-FILE."))
|
||||||
`(with-open-file (,stream ,path :direction ,direction ,@args)
|
`(with-open-file (,stream ,path :direction ,direction ,@args)
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
#:iflet*
|
#:iflet*
|
||||||
#:condlet
|
#:condlet
|
||||||
#:condlet*
|
#:condlet*
|
||||||
#:read-file-string
|
#:read-file-as-string
|
||||||
#:with-string-output-to-file
|
#:with-string-output-to-file
|
||||||
#:with-read-from-file
|
#:with-read-from-file
|
||||||
#:with-write-to-file
|
#:with-write-to-file
|
||||||
|
|
Loading…
Reference in New Issue