Add expansion for defmacro! macros.

This commit is contained in:
Kyle Isom 2015-08-31 22:21:28 -07:00
parent 32a4e9b9bd
commit ca7fb58b38
3 changed files with 17 additions and 19 deletions

View File

@ -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))

View File

@ -92,17 +92,15 @@ 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)

View File

@ -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