From ca7fb58b389121b51dab99b9beb58866631b1842 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Mon, 31 Aug 2015 22:21:28 -0700 Subject: [PATCH] Add expansion for defmacro! macros. --- docs/manual.scr | 10 +++++----- macros.lisp | 24 +++++++++++------------- package.lisp | 2 +- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/docs/manual.scr b/docs/manual.scr index b2a2aae..00fb297 100644 --- a/docs/manual.scr +++ b/docs/manual.scr @@ -226,8 +226,8 @@ some code should be executed based on the results of those bindings. These macros abstract common operations on files. @cl:with-package[name="kutils"]( -@cl:doc(macro read-file-string) -@cl:doc(macro with-string-output-to-file) +@cl:doc(macro! read-file-as-string) +@cl:doc(macro! with-string-output-to-file) @cl:doc(macro with-read-from-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 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".) @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-vector) @cl:doc(function partial) -@cl:doc(macro read-file-string) +@cl:doc(macro! read-file-as-string) @cl:doc(macro sethash) @cl:doc(function symb) @cl:doc(function take) @@ -432,7 +432,7 @@ Alphabetical documentation for all exported symbols. @cl:doc(macro whenlet*) @cl:doc(macro with-new-hash-table) @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(function zip)) diff --git a/macros.lisp b/macros.lisp index 2507f69..3de880e 100644 --- a/macros.lisp +++ b/macros.lisp @@ -92,25 +92,23 @@ resulting string to @c(path). Any remaining arguments are sent to (let ((o!out (mkstr ,@body))) (princ o!out g!s))))) -(defmacro with-read-from-file (path &rest args &key (direction nil directionp) - &allow-other-keys) - "Read the form contained in @c(path), with any remaining arguments -passed to @c(with-open-file)." - (let ((s (gensym))) - (declare (ignore direction)) - (when directionp - (error "Specifying :direction is not allowed with READ-FILE.")) - `(with-open-file (,s ,path ,@args) - (with-standard-io-syntax - (read ,s))))) +(defmacro with-read-from-file ((stream path &rest args &key (direction :input directionp) + &allow-other-keys) + &body body) + "Open @c(path) for reading, bound to @c(stream), with any remaining arguments +passed to @c(with-open-file), and execute @c(body)." + (when directionp + (error "Specifying :direction is not allowed with READ-FILE.")) + `(with-open-file (,stream ,path :direction ,direction ,@args) + ,@body)) (defmacro with-write-to-file ((stream path &rest args &key (direction :output directionp) &allow-other-keys) &body body) "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 - @c(with-open-file)." +value of @c(stream). Any remaining keyword arguments are passed to +@c(with-open-file)." (when directionp (error "Specifying :direction is not allowed with WRITE-FILE.")) `(with-open-file (,stream ,path :direction ,direction ,@args) diff --git a/package.lisp b/package.lisp index 472fc22..0d2043b 100644 --- a/package.lisp +++ b/package.lisp @@ -50,7 +50,7 @@ #:iflet* #:condlet #:condlet* - #:read-file-string + #:read-file-as-string #:with-string-output-to-file #:with-read-from-file #:with-write-to-file