(no title)
aneil | 2 years ago
No, it _is_ because of homoiconicity, which though a fancy word, does mean something: code is data. That is the reason Lisp syntax works. Clojure is less uniform, but it is still homoiconic, and that is why it has the same powers as CL.
kazinator|2 years ago
The POSIX shell is homoiconic because after you have defined some functions, you can execute the command "set" (with no arguments) to see the definitions. They are stored in a form that can be copy and pasted into the shell. (There may be reformatting and comments removed).
The homoiconic feature in Lisp (Common Lisp) is the ED function. It will recall the textual definition of a function, allowing it to be edited.
The big idea in Lisp of using a data structure for manipulating code isn't homoiconic; the data structure definitely isn't in the source code format. It's homoiconic to the extent that uncompiled code can be stored as a data structure and converted back to a character-level of representation. (This is possible due to something that Lisp calls print-read consistency, an important concept in Lisp.)
The code-to-code transformations in Lisp do not work by converting code to text and back again.
We can take advantage of that even if we go through some front-end that provides a surface syntax, like infix.cl, which loses homoiconicity.
So rather that homoiconicity, the two concepts important in Lisp are print-read consistency and code as a data structure.
umanwizard|2 years ago
I think when people say “code is data” what they really mean is something more specific, like the AST is easy to access and manipulate in the language.
freilanzer|2 years ago
(def add (x y) (+ x a))
(def sub (x y) (- x y))
(add 1 2) # 3
(sub 1 2) # -1
(first '(add 1 2)) # 'add
(rest '(add 1 2)) # (list 1 2)
(apply 'sub (rest '(add 1 2))) # -1
(reverse '(add 1 2) # '(2 1 add)
Excuse my pseudo lisp quote syntax, it's been a while.