April 7, 2008
Sequence shuffling wrap-up
This post has two parts, a social and a technical one. Scroll down to see the technical one if you don’t care about the former.
For me, Common Lisp offers two fundamental modes of programming, often mixing together.
The first mode is serious software development (by which I’m attempting to pay my rent right now). Everything needs to work here. Thread safety, correctness, safety over speed, enough speed nonetheless, pragmatism, … well, I guess you know the score.
The second mode is exploration and experiments. My last two posts on the randomization of sequences were just that, and collaboratively that. After all, my blog is neither a newspaper nor a research journal. Unfortunately some readers seem to have misunderstood this. I suppose this is partly owing to my usual portion of kidding hyperbole, like my stating that I were “allergic to consing” and had found an exceptionally “good solution”.
So, to make it clear: both of these posts were not about presenting a well-tested algorithm ready for public copy-and-paste, but something to think about — for you and for me.
Tagging the list’s elements with a random id beforehand, as in the solutions Paul and Phil came up with, is a very nice, solid and working solution. Unfortunately this one is also so straight-forward that it hasn’t much potential for intellectual stimulation (at least not for me), and that’s why I decided to pursue the idea with hash tables and memoization further.
Now for the technical part of this wrap-up: SEQRND works for all objects where EQ reliably points out differences. This definitely excludes literals (the will be constant-folded more often than not) but includes CLOS objects. SEQRND also was three times faster than Paul’s RANDOM-SHUFFLE on SBCL.
My personal bottom line is: use one of the solid algorithms all the time and rely on Fisher-Yates if you need the speed.
Comments(2)
(From your first post:)
> Here?s a quickie for the newbies among you:
> …
From your new post:
> The second mode is exploration and experiments.
> My last two posts on the randomization of
> sequences were just that, and
> collaboratively that.
so also the social part is shuffled ?
> both of these posts were not about presenting
> a well-tested algorithm ready for public
> copy-and-paste, …
… but sufficient for the newbies among us.
> Unfortunately this one is also so straight-forward
> that it hasn?t much potential for intellectual
> stimulation (at least not for me),
This happens also to newbies; get over it !
> Unfortunately some readers seem to have
> misunderstood this.
No, but you are listed on Planet Lisp. This should cause some feeling of responsibility for your chattering.
Xach ! help !
Yeah, you are right (whining aside).
This started as the posting of a neat idea I thought had correct behaviour and only then turned out to be incorrect.
For someone who doesn’t read the follow-up comments and posts it would seem like a good idea to take it without questioning. I’ll add a note at the beginning of the original post to reflect this.
Leslie