3 ms·
How about monkey patching in languages like Javascript and Python? I'd also say "homoiconic" is a less important concept than people would think. A while back
by PaulHoule 2y ago
How about monkey patching in languages like Javascript and Python?
I'd also say "homoiconic" is a less important concept than people would think. A while back I was writing a lodash-like library for Java because I don't like the Streams API (though in the end I just used the collectors from the Stream API because they were easy to fit into my system) One thing I found frustrating about that was that I didn't want to write 8 different functions for the 8 primitive types (never mind 64 functions for the direct product of the primitive types) and conceived of a code generator that would let you write Java-in-Java with a somewhat Lispy looking API that builds up something like S-expressions with typed static imports, here is some sample code
https://github.com/paulhoule/ferocity/blob/main/ferocity0/src/test/java/com/ontology2/ferocity/TestUrFierce.java https://github.com/paulhoule/ferocity/blob/main/ferocity0/sr...
The plan was to write a ferocity0 sufficient to write a code generator that could generate stubs for the standard library plus a persistent collection library, then write most of ferocity1 in ferocity0 and maybe write a ferocity2 in ferocity1 and ferocity2 would be the master tool for code generation in Java. Look how nice the stub generator is
https://github.com/paulhoule/ferocity/blob/main/ferocity0/src/main/java/com/ontology2/ferocity/WrapperGenerator.java https://github.com/paulhoule/ferocity/blob/main/ferocity0/sr...
Now many people would think this combines all the drawbacks of Common Lisp and Java and they might be right. On the other hand, I think if you're aggressive in organizing your code and using code generation you might cut your code volume enough to make up for the bulking that happens when you write Java-in-Java. The stubs to write Java-in-Java are a huge amount of code but they're 99% generated and once you have Java-in-Java you can keep recursing and messing around with quote and eval and do all the stuff you'd do in a homoiconic language except you are having to write code in a DSL.
- kazinator 2y agoNow suppose three of you are working on the same project, and each brings their own code generator like this. You can take Common Lisp macros from multiple sources and use them in the same expression, in any pattern of nesting.
- PaulHoule 2y agoIn principle. Most people find somebody else's metaprogramming-heavy Common Lisp difficult to work with. When you look at classic programs from the golden age of AI you find they either rewrote their Lisp prototype in C++ for speed or the Lisp program (like an expert system shell) is much smaller than you imagine possible but it looks like the engine of a UFO.
- aeonik 2y agoDo you have a link to one of these UFO engines that I can study up on?
- PaulHoule 2y agoSee https://www.cs.unm.edu/~luger/ai-final/code/LISP.ess.html https://www.cs.unm.edu/~luger/ai-final/code/LISP.ess.html and the more modern http://www.clara-rules.org/ http://www.clara-rules.org/
- deleted 2y ago[deleted]
- kazinator 2y agoThat code looks readable to me. It is well formatted and the functions are small, with simple control paths. No variable assignments or loops to unravel. It defines no macros, but refers to some defined elsewhere; the instructions say you are supposed to use a certain other source file related to Chapter 14 of a book. I could probably ramp up on this in a day, if I had reason to.
- kazinator 2y ago> Most people find somebody else's metaprogramming-heavy Common Lisp difficult to work with. Citation needed. Org names, projects, numbers. Also, how easy do people find someone's Java metaprogramming? Where the whole metaprogramming system is locally invented, not just its application to the problem?
- skulk 2y agoI glanced at your code examples and it looks quite similar to ByteBuddy[0], a Java library for manipulating JVM bytecode. [0]: https://github.com/raphw/byte-buddy https://github.com/raphw/byte-buddy