git.fiddlerwoaroof.com
Browse code

feat(streams): helper macro to auto-adapt strings to streams

Edward Langley authored on 28/08/2022 06:42:53
Showing 1 changed files
... ...
@@ -219,6 +219,15 @@
219 219
       `(when ,cond
220 220
          (,op ,arg ,@r)))))
221 221
 
222
+(defmacro str->stream ((op arg &rest r))
223
+  (let ((string (case op
224
+                  (cl:funcall (car r))
225
+                  (t arg))))
226
+    (alexandria:once-only (arg)
227
+      (alexandria:with-gensyms (s)
228
+        `(with-input-from-string (,s ,arg)
229
+           (,op ,s ,@r))))))
230
+
222 231
 (defmacro default-when (default test &body body)
223 232
   "return the default unless the test is true"
224 233
   (warn "default-when is deprecated, renamed to default-unless")