4 ms·
Ask HN: Lisp Macros for Self-Improving AI?
I'm not an expert in Lisp but from what I understand, Lisp macros allow for self-modifying code while the program is running:
https://stackoverflow.com/questions/36416532/lisp-in-ai-self-modifying-code-and-domain-specific-levels-of-abstraction
I was wondering if this is useful for AI that can modify (improve) its own code. Am I missing something?
- Tomte 4y agoNo. Macros are compile-time. Lisp implementations typically give running programs access to the compiler, but that has nothing to do with macros, and then again, other languages do as well.
- eduction 4y agoIf you can compile code at runtime, then how are you not able to use macros at runtime via the same facility? Macros are just functions that operate on the data structures that define function calls prior to those calls being executed, symbols resolved , etc. So if you’re compiling new code at runtime via eval the that code will go through the same process, including macro expansion.
- Tomte 4y agoThe point was that macros are not special, they don't give you anything more for "self-modification".
- eduction 4y agoMacros are special in the sense that they are expressly intended to modify code. I take your implied point that at runtime there is not really a difference between a function designed to rewrite code data structures and evaluate them vs calling macroexpand and using a predefined macro. But it’s going to be more concise at least to do the latter. It’s also probably the case that when people talk about lisp macros they are including facilities that can be used anywhere but are mainly used for macros - backtick quoting, unquoting forms, etc. - as well as macro like activities like having a function designed to rewrite a code data structure at runtime prior to it going to eval (even if defined with defn or defun rather than defmacro).
- lispm 4y ago> Macros are special in the sense that they are expressly intended to modify code Macros are intended to transform code. They are designed such that in compiled code the transformation is only done at compile time.
- lispm 4y agoIf you are going to use EVAL at runtime, then macros don't buy us anything new. calling (eval (generate-some-code)) does already execute newly generated code at runtime.
- PaulHoule 4y agoOther languages are similarly dynamic. For instance a Java program can write Java bytecode and pass it to the the defineClass() method of the classloader and then run the code. Currently fashionable machine learning approaches don't generate general purpose code but instead determine the coefficients for a matrix equation. Notably this kind of "program" is guaranteed to finish, which limits what it can do algorithmically, see https://en.wikipedia.org/wiki/BlooP_and_FlooP https://en.wikipedia.org/wiki/BlooP_and_FlooP but that kind of program can run efficiently on a GPU or similar device because it is a bunch of repetitive math. There are some older algorithms like https://en.wikipedia.org/wiki/C4.5_algorithm https://en.wikipedia.org/wiki/C4.5_algorithm which "learn" rules that look more like ordinary code.
- mindcrime 4y agoThere are some older algorithms like <snip> which "learn" rules that look more like ordinary code. See also, "Rule Induction"[1]. [1]: https://en.wikipedia.org/wiki/Rule_induction https://en.wikipedia.org/wiki/Rule_induction
- mindcrime 4y agoSelf-modifying code (whether it's in Lisp, Java, or "other") could theoretically be useful, but there's a lot of "the devil's in the details" stuff to consider. The first thing that comes to mind is the general idea that for any kind of continually improving system (the obvious analogy would be an evolutionary algorithm[0] of some sort) you need a "fitness function" that dictates whether or not the system is, in fact, improving. And defining the fitness function and the representation that maps from your code to the thing you're trying to improve, is often the hardest part. FWIW, people have explored the intersection of evolutionary algorithms and code generation under the rubric of "Genetic Programming"[1][2][3]. This isn't necessarily the only (or best) such approach, but it's one that has been explored quite extensively and where there is a large body of literature to review. You might find some of that stuff interesting, vis-a-vis this overall topic. [0]: https://en.wikipedia.org/wiki/Evolutionary_algorithm https://en.wikipedia.org/wiki/Evolutionary_algorithm [1]: https://en.wikipedia.org/wiki/Genetic_programming https://en.wikipedia.org/wiki/Genetic_programming [2]: https://geneticprogramming.com/ https://geneticprogramming.com/ [3]: http://www.genetic-programming.org/ http://www.genetic-programming.org/
- cvjcvjcvj 4y agoRuby code can be generated and evaluated in runtime.