Implicit move

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Implicit move

Post by newdep »

Hi Lutz,

I like implicit indexing a lot, it easy to use and compact...

But what i actualy miss inside implicit indexing is a simple way
to "move" variables inside lists...

Normaly I use a pop and a push to move an list/variable inside a list around, but actualy using pop en push is a little clumpsy together with implicit indexing or actualy overall for moving...

I would like to see something like i.e. this ->


> (set 'a '("one" "two" "three"))
("one" "two" "three")
> (nth-move (a 0) (a -1))
("two" "three" "one")

No its not a rotate, because then the function is getting too long again,
perhpas and extra parameter inside nth-set for moving inside lists?

Moving (like in 'pop then push) a nested list inside another nested list...or anything else..

Or perhpasd just a simple 'move function that moves inside lists
and strings...

Would be a nice to have...


Regards,
Norman.
-- (define? (Cornflakes))

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

Hmm, cool ideas!

Perhaps this is not elegant enough...?

Code: Select all

(set 'a '("one" "two" "three")) 
(swap  1 0 (swap -1 0 a))
;-> ("two" "three" "one")

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

heheh... yes your right... i all forgot about 'swap

'swap is indeed useful for simple list swapping, would be nice if it could
be extended with nested-list swapping too ;-)

Thanks for the tip..

Norman..
-- (define? (Cornflakes))

Locked