Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is LISP's code-as-data ideology basically the same thing as higher order functions? [closed]

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?

like image 988
patrickbarker Avatar asked Oct 04 '14 20:10

patrickbarker


1 Answers

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.

like image 132
acjay Avatar answered Sep 21 '22 21:09

acjay