351848b6eab4

Bonus
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 20 Apr 2022 20:10:31 -0400
parents a55e0be16f56
children 1aa828894145
branches/tags (none)
files content/blog/2022/04/fun-with-macros-do-file.markdown

Changes

--- a/content/blog/2022/04/fun-with-macros-do-file.markdown	Tue Apr 19 09:46:21 2022 -0400
+++ b/content/blog/2022/04/fun-with-macros-do-file.markdown	Wed Apr 20 20:10:31 2022 -0400
@@ -241,3 +241,16 @@
 It can take any reader function that conforms to the usual `(read-foo stream
 eof-error-p eof-value)` interface, which means we can write our own reader
 functions that will compose nicely with the macro.
+
+We'll end with an exercise for the reader: figure out how to support
+declarations correctly.  For example:
+
+```lisp
+(do-file (n "numbers.txt" :reader #'read-fixnum)
+  (declare (type fixnum n))
+  (when (primep n)
+    (collect (* n n))))
+```
+
+Hint: you'll need to deal with the sentinel value a bit differently so it
+doesn't contaminate the type of the bound variable.