freenode/lisp - IRC Chatlog
Search
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
4:01:07
npfaro
Yeah, the issue is that I have another `for` clause in the loop that uses one of the previous values, and that value cannot be nil
4:03:17
npfaro
or actually i really didn't, now that i'm coming back to it. i'm just looping over a remove-if
4:03:58
White_Flame
ah, so you're not using the restarts to get around the LOOP iteration, that's okay
4:04:45
White_Flame
you could use ignore-errors, which will return NIL for you on error, but adding the debugging FORMAT might be a bit more verbose
4:06:51
npfaro
Is there anyting analogous to a named let in scheme, other than using flet or labels and calling it?
4:09:48
npfaro
not exactly, because you can call the named let with whatever parameters you want just like a recurisve function
4:10:43
npfaro
do isn't exactly as powerful because you have to define a step form for each var instead of being able to specify it in the body
4:13:00
White_Flame
having a specific entry point wiht initializers seems to be the more accepted style than reusing it for the inner loop
4:16:01
White_Flame
at least in SBCL, self-recursive functions compile down to the proper set as needed & jump code
4:32:05
beach
I have seen so many programs become incomprehensible by someone insisting on using tail recursion rather than iteration.
4:34:56
beach
Also, it is usually a bad idea to use idioms from a different language. That goes for programming languages and natural languages alike.
4:36:16
beach
I say, use recursion when recursion is pretty much the only solution, like on trees and graphs. For linear structures like sequences, iteration is usually preferable.
4:50:28
White_Flame
npfaro: I use tail calls a lot, and tend to use self-recursion whenever it goes beyond simple LOOP usage