slice

Q&A's, tips, howto's
Post Reply
eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

slice

Post by eddier »

Thanks for the new set-nth function!

It would be nice if slice had a negative offset that started from the end of the list instead of the beginning.

Example

Code: Select all

(setq a '(1 2 3 4 5 6 7))
(slice a -3 2) => (5 6)
This is somewhat nicer than

Code: Select all

(slice a (- (length a) 3) 2)
Eddie

Lutz
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

>>>>
It would be nice if slice had a negative offset that started from the end of the list instead of the beginning.
>>>>

I was thinking about this too, sounds like a good idea for the next release. (Could also be done in nth and set-nth)

Lutz

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post by eddier »

... and push, pop, and char.

Eddie

Lutz
Posts: 5279
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

... and lookup, swap, collect, select

lets do them all ;), the thing is, if you (as a user) find it in one function, it is intuitive and expected to have it in all primitives, which use and index/offset spec.

I went looking through the code and I think it is doable without sacrifying (measurable) speed for the normal positive offset and with very little code, the mechanism, how to do it, is always the same.

Lutz

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post by eddier »

I agree! Consistency is always best :)

Eddie

Post Reply