Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your forms appear to be nested improperly.</p> <pre><code>(if test true-branch &amp;optional false-branch) </code></pre> <p>in this case is binding</p> <pre><code> test = ((and (car p1) (car p2)) nil) true-branch = (princ (car p1)) false-branch = nil </code></pre> <p>you probably wanted</p> <pre><code> (if (and (car p1) (car p2)) nil (princ (car p1))) </code></pre> <p>which is more usually written as</p> <pre><code> (unless (and (car p1) (car p2)) (princ (car p1))) </code></pre> <p>which is somewhat strange because you know that <code>(car p1)</code> <em>may be</em> <code>nil</code> at that point, (except <code>(car p2)</code> could be <code>nil</code>), so it may then be the same as</p> <pre><code> (unless (and (car p1) (car p2)) (princ nil)) </code></pre> <p>half the time, so perhaps you meant rather like</p> <pre><code> (when (and (car p1) (car p2)) (princ (car p1)) </code></pre> <p>which is the same as</p> <pre><code> (if (and (car p1) (car p2)) (princ (car p1))) </code></pre> <p>(but the use of <code>when</code> or <code>unless</code> helps others reading your code, so we won't have to puzzle over the forms to make sure that there isn't an “<code>else</code>-clause” hiding in there that we haven't noticed)</p> <p>So, I'm not really sure what you're trying to do there.</p> <p>⁂ Note on how your compiler will interpret what you've written a bit further:</p> <pre><code> ((and (car p1) (car p2)) nil) </code></pre> <p>is a particularly problematic-looking form, because this is what will happen:</p> <pre><code> (eval (car p1)) (eval (car p2)) </code></pre> <p>let's call these results for now <code>cp1</code> and <code>cp2</code></p> <pre><code> (eval (and cp1 cp2)) </code></pre> <p>OK, so if <code>cp1</code> (i.e. <code>(car p1)</code>) is <code>nil</code>, it has just become the value of the form; if it <em>is not</em> <code>nil</code>, then <code>cp2</code> will become the value of the form.</p> <p>So, the results of this form are one of two things: <code>nil</code>, or <code>cp2</code> (which could be <code>nil</code>) Let's call this result <code>f</code></p> <p>The next form outward, though, is the problem:</p> <pre><code> (eval ((function f) nil)) </code></pre> <p>You see, the <code>(and…)</code> form is in the <code>car</code> of the surrounding form, so the compiler is going to have to try to coërce the results of that form into a <code>funcall</code>able object, as though you'd called the function <code>function</code> on it.</p> <p>Now, if <code>f</code> (i.e. <code>(and (car p1) (car p2))</code>) happens to be a reference to a function, <em>and</em> that function can be called with a single parameter, then you might be OK.</p> <p>But the fact that you're trying to <code>princ</code> the results of <code>(car p1)</code> suggests that the contents are likely a <code>string</code>, <code>character</code>, or <code>number</code>, and none of those are going to return a function pointer when passed to <code>function</code>. </p> <p><strong>Lesson to take home</strong>: Watch your parentheses :-)</p> <p>Also… the output from your compiler or debugger should probably have given you some strong hints about what was going wrong here. In future, it'd be quite helpful to show</p> <ul> <li>what parameters you're passing in to the function, and</li> <li>what your output from the compiler or debugger is that let you know you have a problem</li> </ul>
    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