4 ms·
The main advantage that I see is that his class transparently works with any function expecting a 'sequence', which spec only defines as either a vector (i.e.,
by smanek 18y ago
The main advantage that I see is that his class transparently works with any function expecting a 'sequence', which spec only defines as either a vector (i.e., 1-d array) or a list (i.e., linked list) while providing a some (extremely simple) lazy evaluation. I, for one, never realized that you could extend the sequence type in this way in SBCL.
For example, if he created an instance of his interval-sequence class with (below 100000000), he wouldn't actually have to allocate the memory for a hundred million element vector (or a 100 million cons cells). Instead, it would just use a handful of bytes to represent the start of the sequence, and the length.
By itself, it's fairly trivial. But, this sort of manipulation isn't part of the ansi spec so this post was just sort of letting us know what was possible (a 'hello world' of sorts).
I already have a few interesting ideas on how one could use this same technique to provide slightly smarter lazy evaluation, and some sort of time/duration manipulation stuff.
- sgk284 18y agoI'm a big python user, with some lisp coding in the past. I took a look at his code and I'm just wondering if this is any different than xrange() in python? For those that don't know, xrange is a generator of integer sequences... a way of iterating a "list" of N integers while only allocating space for 1 integer. *note: This isn't a "python is better" argument, it's an "I'm surprised sbcl doesn't provide xrange type functionality, am I right in that assumption" argument.
- BrandonM 18y agoIt looked like xrange to me. Honestly, though, I can see why it's not in SBCL, because I don't actually find myself using xrange all that much. It's mostly stuff like: for unused in xrange(500): # perform some operation (500 times) In Lisp, this is just: (dotimes (unused 500) ; perform some operation... )