Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>/</code> takes as arguments one or more numbers, but in your code you're passing it a list - clearly this will not work. The function <code>apply</code> is your friend here - <code>(apply #'foo a b (list c d e))</code> is equivalent to <code>(foo a b c d e)</code>. Note the the arguments to <code>apply</code> between the function to use and the final list are optional, so <code>(apply #'/ '(20 2 5))</code> is equivalent to <code>(/ 20 2 5)</code>.</p> <p>Also, your attempt at removing zeros will not work. <code>dolist</code> is evaluating its body for each item in the argument list <code>elements</code>, but you're not actually doing anything to change the content of <code>elements</code> (the result of evaluating <code>dolist</code> s body is not reassigned to the source element as you seem to expect).</p> <p>The functions <code>remove-if</code> (and its destructive counterpart, <code>delete-if</code>) are what you are looking for. The following shows how to use it (it takes lots of optional arguments, which you don't need to worry about for this purpose).</p> <pre><code>(defun divtest (elements) (apply #'/ (remove-if #'zerop elements))) </code></pre> <p>Also note that this won't behave correctly if the <code>elements</code> list has zero as its first element (assuming I understand what the function's meant to do). So you might instead want something like</p> <pre><code>(defun divtest (elements) (apply #'/ (first elements) (remove-if #'zerop (rest elements)))) </code></pre> <p>See the Hyperspec for more details.</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