Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>Use a function</h1> <p>If you want to use a function, you have to pass the symbol itself:</p> <pre><code>(defun mutate (symbol value) (setf (symbol-value symbol) value)) (mutate 'foo 42) foo ==&gt; 42 </code></pre> <p>Note that the <code>symbol</code> argument to <code>mutate</code> is quoted.</p> <h1>Use a macro</h1> <pre><code>(defmacro mutate (symbol value) `(setf ,symbol ,value)) (mutate foo 42) foo ==&gt; 42 </code></pre> <p>The <code>symbol</code> argument no longer has to be quoted.</p> <h1>Discussion</h1> <p>Arguments are <a href="http://www.lispworks.com/documentation/HyperSpec/Body/03_ababc.htm" rel="nofollow">passed by value</a> in Lisp, which means that a function sees the <em>value</em> of its argument, not the place where it is stored. Thus a function invoked as <code>(foo (! 5))</code>, <code>(foo 120)</code>, <code>(foo x)</code> sees only the number <code>120</code> and has absolutely no way of knowing whether this number is returned by a function (1st case), is a literal (2nd case) or stored in a variable (3rd case).</p> <p>Macros receive <a href="http://www.lispworks.com/documentation/HyperSpec/Body/03_ababb.htm" rel="nofollow">the <em>code</em> (the whole form)</a> which they <em>transform</em> and pass the new code to the compiler (or interpreter). Thus macros can determine how to modify their arguments (called <a href="http://www.lispworks.com/documentation/HyperSpec/Body/05_aa.htm" rel="nofollow"><em>places</em> or <em>generalized references</em></a> in that case).</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. 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