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
0:05:06
npfaro
When I write it to a file with `with-standard-io-syntax` and `prin1`, it comes out like this: (13 #A((17) BASE-CHAR . "ERROR 13, 5621064"))
0:06:06
npfaro
Here's the expression which evaluates to create the '(13 "ERROR 13, xxxx) list: (list (format nil "ERROR ~a, ~a" (car x) (cdr x)))
0:07:42
pfdietz
SBCL's read table has an option for converting strings (on reading) to base strings, if all the characters are base chars. I am wondering if the standard io syntax has that bit set. If not, then to print readably it has to use that weird syntax.
0:09:06
pfdietz
But if you read them and the bit is not set, you should get a string (with element-type CHARACTER) not a base-string (with element-type BASE-CHAR).
0:10:26
pfdietz
Check if the string is of type (array base-char (*)), or of type (array character (*)).
0:18:17
Bike
prin1 prints readably, so it goes through extra effort to prefer stuff like element type that a human reader wouldn't so much care about
0:18:20
pfdietz
You could bind *print-readably* to nil inside the with-standard-io-syntax. Failing that, you could play with pprint dispatch tables to make it do something differently on strings.
0:19:30
Bike
i mean, conceptually if you're using standard io syntax and prin1, you presumably are printing something with the aim of reading it back later
0:38:03
npfaro
that's fair enough, although I intended to dump a form out to a file so that I (and potentially others) could edit it as they please, and then load it back in again
0:50:34
Alfr_
npfaro, you could resort to coercing format's result to a (simple-array character (*)) .
0:53:16
Alfr_
npfaro, prin1 may output anything it likes, as long as it can be read back to recreate something similar to what was printed.
1:20:56
npfaro
I have something like (loop for x in ls when (not (member x other-ls)) for y = (car x) do ...) but I'm getting an error