Mar 03, 2006 18:52
I need an simple example of self modifying LISP code from which I can learn and go forth and do evil. Google is being uncharacteristicly unhelpful. Do any of you know of such, or for that matter a repository of good LISP examples period? The future of the world (ok, just this quarter) depends on you!
Leave a comment
Comments 4
But I'm still having trouble tracking down some good eval examples...
Reply
(The comment has been removed)
Reply
I guess that doesn't really answer your question. Supposedly (eval) is your main weapon here. Give it a list and it will run that list just as it was a piece of source code. Here's an example from Common Lisp the Language:
(eval (list 'cdr (car '((quote (a . b)) c)))) => b
Obviously this isn't a self-modifying line of code, but it demonstrates what eval does. You could easily store eval's argument (the list above) in a variable and then change parts of it if you need to.
The real question is what do you want to do with self-modifying code? It's not really useful except in very specific circumstances (like a virus changing its code to evade virus detectors, ie "polymorphism". However, no one writes viruses in LISP, and the re-written code is usually ( ... )
Reply
Longer answer: in AI this quarter, for the last tournament, we have the option of either returning a play, or returning a lambda function that acts on the top 5 plays (unless you're in the top 5). It would be nice to be able to tune and tweak that lambda function on the fly as we learn, but to do that, that probably means self modifying code.
And because it's cool. :)
Reply
Leave a comment