freenode/lisp - IRC Chatlog
Search
10:20:06
phoe
|3b|: he wants efficience, I think destructive splitting of conses is going to be as efficient as he can get it
10:21:08
phoe
if you want programmer effiicience, alternatingly push into two lists, then nreverse them
10:21:39
|3b|
(loop for (a b) on (sort ...) by #'cddr collect a into as when b collect b into bs finally (return (list as bs)))
10:21:45
axion
Doesn't have to be 'fastest possible' but this will occur with every page load, so milliseconds count.
10:23:10
|3b|
even then, cache when they change rather than on access might win unless they changee more than they are read
10:23:11
jackdaniel
because it doesn't cons unnecessarily, doesn't reverse and keeps pointer to the list end
10:23:58
jackdaniel
oh, sorry, uiop:while-collecting does a lot of things, I'd go with cmuutil collect macro after all
10:24:22
|3b|
ACTION also notes that the performance loss from non-destructive split probably wouldn't show up on that page load anyway :p
10:25:52
phoe
my algorithm: grab references to 1st and 2nd cons of the list. set the CDR of the first cons to the 3rd cons, set the CDR of the first cons to the CDDDR of the first cons, set the CDR of the second cons to the CDDDR of the second cons. Use the CDRs of the first and second cons as the new values for the first and second cons, loop until the CDRs of the lists are NIL.
10:26:50
axion
The simplest code can be continually made 'fastest possible' over a lifetime for a programmer. I should have known better to phrase that a bit better
10:30:16
|3b|
loop/collect version sorts/splits the symbols from CL: in a little over 1.6 million cycles
10:33:12
axion
beach: So is a lot of things here, such as algorithm efficiency and Emacs buffer data structures being a bad data structure for their use :)
10:39:32
axion
I guess there's nothing wrong with it really. I just didn't expect a 2 element list of NIL's if given an initiallly empty list
10:40:26
axion
|3b|: What is the point of the WHEN clause? I don't see when it would change anything
10:47:15
axion
phoe's implementation is extremely fast, but I was expecting that keeping a reference to tail
13:09:20
rk[ghost]
maybe so. but even something like nth it is taking me a while to be like, use that and quit doing strange caaaddars..
13:11:08
rk[ghost]
i find i spend more time trying to decide how fancy to be about a solution rather than just solving it and moving on.
13:14:41
rk[ghost]
it would probably suit me to spend a few days reading the common lisp hyperspec more or reading others code more than programming.. as it seems like every day i come across a new library function which implements something i already spent time implementing by hand.
13:24:22
pjb
rk[ghost]: notice that: (let* ((k1 "k1") (k2 "k2") (a (acons k1 1 (acons k2 2 nil)))) (assoc k2 a)) #| --> ("k2" . 2) |# works perfectly with strings and without :test.
13:26:12
pjb
rk[ghost]: on the other hand: (assoc :foo '((bar . 1) (foo . 2))) #| --> nil |# doesn't work as you expect without :test! (assoc :foo '((bar . 1) (foo . 2)) :test (function string=)) #| --> (foo . 2) |#
13:35:41
axion
shka_: It doesn't make much sense to use an intermediary vector when the input and output must be a list as mentioned
18:50:09
flip214
When the accessor functions for a class are in a different package, is there a shorter way than the 2-symbols-version of WITH-ACCESSORS to map them to symbols in the local package?