Is LISP the idea of ​​code data as the same as higher order functions?

So, I tried to get my head around the idea of ​​the clojure code-as-data approach, and this is definitely a bit confusing. It looks like they are just functions of a higher order. Is there a difference between the two?

+5
source share
2 answers

Code data is a big step forward. HOF gives you data code in the sense that you can transfer executable blocks to other executable blocks and compose them. But you cannot manipulate the structure of the blocks themselves. This is similar to working with objects that have only one method (function call), but otherwise there is no data leak.

In complete generality, code-data implies that code works like any other data structure in your environment, with content that you programmatically manage. The homoconicity of @coredump makes this a lot easier, because you can use the same operations and transformations for the code block that you can apply to any other native data structure. But homoconicity is not strictly required. Many non-homiconic languages ​​provide metaprogramming features that can achieve similar results, such as Scala macros and quasiquotes (for processing code at compile time) and toolbars (for runtime) or Python ast .

+12
source

Code as data is more about homoiconicity and writing code that writes code as a whole. You can use functions of a higher order for this, but more about macros. When you take some code, convert it and return some other code, it will be appreciated.

0
source

Source: https://habr.com/ru/post/1204017/


All Articles