So, I've been trying to wrap my head around the idea of clojure's code-as-data approach and it is definitely a bit confusing. It seems a lot like they are simply higher order functions of the sort. Is there a difference between these two concepts?
Code-as-data is a big step further. HOF gives you code-as-data in the sense that you can pass executable blocks into other executable blocks, and compose them. But you can't manipulate the structure of the blocks themselves. It's kind of like working with objects that have only one method (call the function) but otherwise leak no data.
In full generality, code-as-data implies the code works like any other data structure in your environment, with contents you manipulate programatically. The homoiconicity @coredump mentioned greatly facilitates this because you can employ the exact same operations and transformations to a code block that you can apply to any other native data structure. But homoiconicity isn't strictly required. A lot of non-homoiconic languages provide metaprogramming features that let you achieve similar results, like Scala's macros and quasiquotes (for compile-time code manipulation) and toolboxes (for run-time complilation) or Python's ast.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With