The code compiles but results in a runtime crash - presumably because
the remove-if-not function calls the lambda with a single argument but
the lambda declared doesn't take one.
Adding the (cons x()) sorts this out as you suggested.
I think I prefer the (declare (ignore x)) declaration though as this
just makes the code intent that bit clearer - to me anyway.
Many Thanks
On Jan 28, 9:59 pm, Christopher Allen-Poole <christoph...@allen-
poole.com> wrote:
> Have you tried getting rid of the "x" in this line:
> (cops (remove-if-not (lambda (x)
> If your compiler has difficulty with that, you could always add this
> right after:
> (cons x ()) ; Creates a cons cell which uses that value.
> On Jan 28, 7:06 am, Purity Control <cr...@craigferry.net> wrote:
> > My compiler is throwing up a style error when compiling the make-city-
> > edges function (listed on page 139).
> > It is complaining that the x variable in the lambda function is never
> > being called.
> > I can see why the x variable is not being used (we are just randomly
> > deciding which items should stay in the list and which should not)
> > What I was wondering was whether there was a "cleaner" way to write
> > the function so that no style errors were brought up by the compiler
> > code:
> > (defun make-city-edges ()
> > (let* ((nodes (loop for i from 1 to *node-num*
> > collect i))
> > (edge-list (connect-all-islands nodes (make-edge-list)))
> > (cops (remove-if-not (lambda (x)
> > (zerop (random *cop-odds*)))
> > edge-list)))
> > (add-cops (edges-to-alist edge-list) cops )))