freenode/#lisp - IRC Chatlog
Search
22:30:50
manualcrank
hey guys, according to CLHS for SORT, "The sorting operation can be destructive in all cases."
22:34:50
manualcrank
turns out (loop for list across array-of-lists do (sort list #'<)) was dropping list elements
22:38:50
manualcrank
but if it were destructive then that loop would work, instead i have to do something like
22:48:59
manualcrank
seems to imply the argument may be modified in order to return a correct result
22:51:45
Bike
manualcrank: "destructive" doesn't mean the argument is changed to be sorted, it means the argument is changed
22:53:13
Bike
as for "can be destructive in all cases", that means an implementation can decide when it's destructive.
22:53:20
manualcrank
i guess i was used to sort's behavior with arrays of fixnums, which always did the expected thing
22:53:42
Bike
use the return value. the argument is destroyed. don't use it any more, even if it looks right on your particular implementation.
23:00:57
no-defun-allowed
well, if you give SORT some conses, it'll adjust the CDRs to taste and it's more than possible whatever cons was first before SORTing could be in the middle
23:02:06
no-defun-allowed
and conses aren't passed by "reference" in a way like arrays are, if you move conses around, there's no telling which is first
23:06:05
aeth
A cons in C terms is (probably, no guarantees) basically just a container of two pointers (actually, more like the union of pointers and the types small enough to fit in the word size with the type tag included). And a list is just something that starts with that or NIL. And a proper list is a list whose final CDR is NIL.
23:06:30
aeth
So with a destructive sort, your list reference could now be pointing to the middle since there is no outer container, just cons-or-NIL.
2:06:18
alexanderbarbosa
"off-topic": as they said, python *is* a good start for those that come from lisp languages. im feeling at home...
2:13:25
no-defun-allowed
alexanderbarbosa: https://www.reddit.com/r/LispMemes/comments/b9phzx/best_lisp_joke_in_existence/
2:14:58
alexanderbarbosa
no-defun-allowed: I was after any pl that was not that weird, by weird i mean, not lispy
5:39:22
LdBeth
However if you want to change the default option there’s :save-runtime-options for save-lisp-and-die