moving an element of a list to another list
Re: moving an element of a list to another list
See also Anaphora.
-
- Posts: 406
- Joined: Sat Mar 07, 2009 6:17 pm
- Location: Brazil
- Contact:
Re: moving an element of a list to another list
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.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.
-
- Posts: 117
- Joined: Tue Aug 10, 2010 11:24 pm
- Location: Calgary, Alberta
- Contact:
Re: moving an element of a list to another list
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 =).
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 =).
Need an online wiki database? My Lisp startup http://www.formlis.com combines a wiki with forms and reports.
-
- Posts: 447
- Joined: Sat Jun 28, 2008 7:49 am
- Location: Austin, TX
- Contact:
Re: moving an element of a list to another list
Just a quibble... That should be "anaphoric," not "anamorphic."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.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/