Browse code
Adding support for &rest arguments in printers.
Now, when using define-message, you can use (:rest ...) to automagically
pick up all the rest of the items passed to the function.
Also, moved the format string compilation to a let surrounding the
function.
Showing 1 changed files
... | ... |
@@ -173,9 +173,11 @@ |
173 | 173 |
,@args)) |
174 | 174 |
|
175 | 175 |
(defmacro define-message (name (&rest args) &body spec) |
176 |
- (with-gensyms (stream) |
|
177 |
- `(defun ,name (,stream ,@args) |
|
178 |
- (&format ,stream ,spec ,@args)))) |
|
176 |
+ (with-gensyms (fs stream the-rest) |
|
177 |
+ `(eval-when (:load-toplevel :compile-toplevel :execute) |
|
178 |
+ (let ((,fs (make-format-string ',spec))) |
|
179 |
+ (defun ,name (,stream ,@args &rest ,the-rest) |
|
180 |
+ (apply #'format (list* ,stream ,fs ,@args ,the-rest))))))) |
|
179 | 181 |
|
180 | 182 |
(define-format-chars |
181 | 183 |
|
... | ... |
@@ -229,7 +231,8 @@ |
229 | 231 |
(:new-line (#\%)))) |
230 | 232 |
|
231 | 233 |
(define-message hello (name) |
232 |
- "Hello " :str) |
|
234 |
+ (:titlecase () "hello" #\space :str)) |
|
233 | 235 |
|
234 |
-(define-message print-comma-separated (values) |
|
235 |
- (:map () :str :exit ", ")) |
|
236 |
+(define-message print-comma-separated () |
|
237 |
+ (:own-line () |
|
238 |
+ (:rest () :str :exit ", "))) |