Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Grand Theft Wumpus Code Style Question
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Purity Control  
View profile  
 More options Jan 28 2011, 7:06 am
From: Purity Control <cr...@craigferry.net>
Date: Fri, 28 Jan 2011 04:06:23 -0800 (PST)
Local: Fri, Jan 28 2011 7:06 am
Subject: Grand Theft Wumpus Code Style Question
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 )))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phil Rand  
View profile  
 More options Jan 28 2011, 1:09 pm
From: Phil Rand <philr...@gmail.com>
Date: Fri, 28 Jan 2011 10:09:32 -0800
Local: Fri, Jan 28 2011 1:09 pm
Subject: Re: Grand Theft Wumpus Code Style Question

On Fri, Jan 28, 2011 at 4:06 AM, Purity Control <cr...@craigferry.net>wrote:

You might try inserting an ignore declaration here:

  (declare (ignore x))

That tells lisp not to worry if you never use x, and in fact, to
warn you if you do refer to x.  (I haven't tried this myself.)

>                                (zerop (random *cop-odds*)))
>                              edge-list)))
>    (add-cops (edges-to-alist edge-list) cops )))

--
Phil Rand
philr...@gmail.com
philr...@pobox.com

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Purity Control  
View profile  
 More options Jan 28 2011, 1:50 pm
From: Purity Control <cr...@craigferry.net>
Date: Fri, 28 Jan 2011 10:50:58 -0800 (PST)
Local: Fri, Jan 28 2011 1:50 pm
Subject: Re: Grand Theft Wumpus Code Style Question
Thank you very much,

Have just tried this and it works a treat.
It elegantly clarifies the functions intention as well.

Craig

On Jan 28, 6:09 pm, Phil Rand <philr...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christopher Allen-Poole  
View profile  
 More options Jan 28 2011, 4:59 pm
From: Christopher Allen-Poole <christoph...@allen-poole.com>
Date: Fri, 28 Jan 2011 13:59:07 -0800 (PST)
Local: Fri, Jan 28 2011 4:59 pm
Subject: Re: Grand Theft Wumpus Code Style Question
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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Purity Control  
View profile  
 More options Jan 30 2011, 7:43 pm
From: Purity Control <cr...@craigferry.net>
Date: Sun, 30 Jan 2011 16:43:31 -0800 (PST)
Local: Sun, Jan 30 2011 7:43 pm
Subject: Re: Grand Theft Wumpus Code Style Question
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-


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »