Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>In the first version <code>(+ 1 2 3)</code> is raw code, whereas in the second version it is data. By assuming the truth of this statement it can be argued that Lisp isn't even homiconic. The code has the same representation as data in the sense that they are both lists/trees/S-expressions. But the fact that you have to explicitly mark which of these lists/trees/S-expressions are code and which are data to me seems to say that Lisp is not homiconic after all.</p> </blockquote> <p>This is not true. In the first version, the list <code>(+ 1 2 3)</code>, which is data, is being fed to the interpreter to be executed, i.e. to be <em>interpreted as code</em>. The fact that you have to mark s-expressions as being code or data <em>in a specific context</em> does not make Lisp non-homoiconic.</p> <p>The point of homoiconicity is that all programs are data, not that all data are programs, so there is still a difference between the two. In Lisp, <code>(1 2 3)</code> is a valid list but not a valid program since an integer is not a function.</p> <p>[If we look at the other great homoiconic programming language, Prolog, then we see the same phenomenon: we can build a data structure <code>foo(X, 1, bar)</code>, but without a definition of <code>foo</code>, we can't execute it. Also, variables cannot be the names of predicates or facts, so <code>X.</code> is never a valid program.]</p> <p>Lisp is self-modifying to a great degree. E.g., here's how to change the definition of a function:</p> <pre><code>[1]&gt; (defun foo (x) (+ x 1)) FOO [2]&gt; (defun bar (x) (+ x 2)) BAR [3]&gt; (setf (symbol-function 'foo) #'bar) #&lt;FUNCTION BAR (X) (DECLARE (SYSTEM::IN-DEFUN BAR)) (BLOCK BAR (+ X 2))&gt; [4]&gt; (foo 3) 5 </code></pre> <p>Explanation: at <code>[1]</code>, we defined the function <code>foo</code> to be the add-1 function. At <code>[2]</code>, we defined <code>bar</code> to be the add-2 function. At <code>[3]</code>, we reset <code>foo</code> to the add-2 function. At <code>[4]</code>, we see that we've successfully modified <code>foo</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload