Page 2 of 2

Re: moving an element of a list to another list

Posted: Fri Nov 05, 2010 12:03 pm
by nuntius
See also Anaphora.

Re: moving an element of a list to another list

Posted: Fri Nov 05, 2010 1:11 pm
by gugamilare
Warren Wilkinson wrote:There is one problem --- what happens if you steal item 0 from a list? It won't work, and it cannot be made to work because steal is a utility function, and it would be unwise to hardcode it so it would setf *test-input* to (cdr *test-input*) for the zero case.
That is the reason I chose to write a macro, not a function. And, since pop-nth (or steal) is a generalization of pop, which is a macro, it feels more natural to me that it is also pop-nth is coded as a macro. Writing a macro also allows a non-destructive version, which is important if your lists share tails.

Re: moving an element of a list to another list

Posted: Fri Nov 05, 2010 9:40 pm
by Warren Wilkinson
Your right in that a non-destructive version of steal can't be made because it would have to save the functionally updated list somewhere, which would be outside knowledge.

I used a function out of personal habit. I'll try to change problems slightly (i.e. using sentinals) to allow a function based solution before I try macros. Macros have a way of growing; a little here.. another macro there... a extra conditional to its output here... etc. You can have some pretty flimsy towers built on macros.

Mostly I just want to keep things simple and macros can sometimes be a crutch that makes a bad design work. This is not one of those times, but I've got my macro-rare style internalized now =).

Re: moving an element of a list to another list

Posted: Thu Nov 11, 2010 7:51 pm
by findinglisp
Warren Wilkinson wrote:The 'a' stands for anamorphic. Paul Graham's 'On Lisp' has it (and anamorphic if, cond, etc), but I think the technique is older than that still. PG also has the definition of 'with-gensyms'. I won't go into details since PG explains it in that book, which is freely available as a downloadable pdf at http://www.paulgraham.com/onlisp.html.
Just a quibble... That should be "anaphoric," not "anamorphic."