freenode/lisp - IRC Chatlog
Search
17:01:34
VincentVega
Hmm can I write my own reader macro that start with #+, e.g. #+my-reader or would it conflict with #+sbcl and such?
17:10:53
phoe
named-readtables provides an in-readtable macro that you can use similarly to in-package at the top of the file
18:47:34
pfdietz
I definitely suggest using named-readtables. Also, use readtable changes sparingly.
18:52:55
aeth
reader macros are good if (0) they're dispatch reader macros starting with # like #z; (1) the thing they work on is contained within parentheses like #z() such as #z(42) not #z42; and (2) they expand into a macro that does all of the actual processing
18:54:07
aeth
That is, if you wanted to have literal hash table syntax as #h(...) like some libraries do, have that turn into (hash ...) which actually does the logic. So #h(:foo 42 :bar 43) would just become (hash :foo 42 :bar 43) which in turn does MAKE-HASH-TABLE with the two PSETFs
18:54:53
aeth
But I never write reader macros because virtually all of the time when I start with the first step (writing the regular macro first) that's all I wind up wanting to use.
18:56:20
aeth
Also note that the example macro uses plists. Always use plists. They're so easy to process in macros because you can just use destructuring-bind to treat them as &key arguments, or you can iterate over the plists two at a time (key and value), depending on what you're doing.
19:14:07
flip214
aeth: even better, just use alexandria's (plist-hash-table ...) --- but you might need to specify the test to be used...
19:39:19
aeth
flip214: The way to specify settings (e.g. hash table test) in a macro like that is probably to have an optional options list at the front. So if the CAR of the body is a list, then it's options and the CDR is a plist tail, otherwise it's a key and the entire body is the plist