Page 1 of 1

Implicit move

Posted: Thu Sep 13, 2007 9:19 pm
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.

Posted: Thu Sep 13, 2007 10:25 pm
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")

Posted: Thu Sep 13, 2007 10:35 pm
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..