Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
help with function please
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
  11 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
 
david  
View profile  
 More options Mar 1, 3:53 pm
Newsgroups: comp.lang.lisp
From: david <not...@gmail.com>
Date: Sun, 1 Mar 2009 12:53:08 -0800 (PST)
Local: Sun, Mar 1 2009 3:53 pm
Subject: help with function please
i attempt to rewrite function illegalp as below. is not working.
please help.
thanks, david

(defclass chessboard ()
  ((board-position :accessor state
                   :initform (make-array '(8 8) :initial-element '0))))

(defmethod put-piece ((board chessboard) x y p)
  (setf (aref (state board) x y) p))

(defun get-four-unique-random-numbers ()
  (loop
     :with results = '()
     :for alea = (random 64)
     :while (< (length results) 4)
     :do (pushnew alea results)
     :finally (return results)))

(defun rank-file (position)
  (multiple-value-bind (quotient remainder)
                       (truncate position 8)
    (list  quotient  remainder)))

(defun reverse-rank-file (lst)
  (let ((x (first lst))
        (y (second lst)))
    (+ y (* 8 x))))

(defun get-positions ()
  (mapcar #'cons '(wk wn wb bk) (get-four-unique-random-numbers)))

(defun neighbor (x)
  (list (1- x) x (1+ x)))

(defun bad-squares (wk)
  (let ((bad-squares (loop for x in (neighbor (first wk))
                      append (loop for y in (neighbor (second wk))
                                collect (list x y)))))
   bad-squares))

(defun illegalp (wk bk)
  (member (reverse-rank-file bk)
          (mapcar #'reverse-rank-file (bad-squares wk))))

(defun new-ill ()
           (let* ((lst (get-positions))
                  (wk (cdr (assoc 'wk lst)))
                  (bk (cdr (assoc 'bk lst))))
                     (member (reverse-rank-file bk)
                             (mapcar #'reverse-rank-file (bad-squares wk)))))


    Reply to author    Forward  
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.
david  
View profile  
 More options Mar 1, 4:03 pm
Newsgroups: comp.lang.lisp
From: david <not...@gmail.com>
Date: Sun, 1 Mar 2009 13:03:28 -0800 (PST)
Local: Sun, Mar 1 2009 4:03 pm
Subject: Re: help with function please
also, function bad-squares does not care if piece is on the
edge of the board. i thought it does not matter so much.
what would lisp experts think about this?
thanks, david

    Reply to author    Forward  
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.
david  
View profile  
 More options Mar 1, 4:06 pm
Newsgroups: comp.lang.lisp
From: david <not...@gmail.com>
Date: Sun, 1 Mar 2009 13:06:29 -0800 (PST)
Local: Sun, Mar 1 2009 4:06 pm
Subject: Re: help with function please
also i think i see problem.
two different types of wk and bk.
but i have to go to work.
later lispers.

    Reply to author    Forward  
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.
Thomas A. Russ  
View profile  
 More options Mar 2, 1:53 pm
Newsgroups: comp.lang.lisp
From: t...@sevak.isi.edu (Thomas A. Russ)
Date: 02 Mar 2009 10:53:11 -0800
Local: Mon, Mar 2 2009 1:53 pm
Subject: Re: help with function please

david <not...@gmail.com> writes:
> also, function bad-squares does not care if piece is on the
> edge of the board. i thought it does not matter so much.
> what would lisp experts think about this?

I would tend to make the function correct, instead of ignoring the
off-board positions.

For you current application, this doesn't matter, but by taking the time
to do a well-formed function definition now, you save the need to go
back and fix bugs if you suddenly decide that you can use this same
function to, for example, show where the king can legally move.

So, part of good software engineering and design is to try to think
beyond the immediate problem and make modular pieces (functions) that
encapsulate some domain-relevant and more general function.  That allows
your code to be extensible and reusable without the need to do a lot of
re-writing (not to mention forgetting about those shortcuts 3 months
from now when you try to make changes.)

At the very least, make sure you document any of these assumptions or
shortcuts that you take in the code comments.

--
Thomas A. Russ,  USC/Information Sciences Institute


    Reply to author    Forward  
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.
Thomas A. Russ  
View profile  
 More options Mar 2, 1:49 pm
Newsgroups: comp.lang.lisp
From: t...@sevak.isi.edu (Thomas A. Russ)
Date: 02 Mar 2009 10:49:54 -0800
Local: Mon, Mar 2 2009 1:49 pm
Subject: Re: help with function please

david <not...@gmail.com> writes:
> i attempt to rewrite function illegalp as below. is not working.
> please help.
> (defun illegalp (wk bk)
>   (member (reverse-rank-file bk)
>      (mapcar #'reverse-rank-file (bad-squares wk))))

You need to specify the :TEST argument to MEMBER.

You are testing for list equality, and the default test of EQL will not
do what you want. (Hmmm.  I didn't notice that in my other reply).

 Try

(defun illegalp (wk bk)
  (member (reverse-rank-file bk)
          (mapcar #'reverse-rank-file (bad-squares wk))
          :test #'equal))

or more simply:

(defun illegalp (wk bk)
  (member (rank-file bk) (bad-squares wk) :test #'equal))

--
Thomas A. Russ,  USC/Information Sciences Institute


    Reply to author    Forward  
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.
William James  
View profile  
(1 user)  More options Mar 3, 2:06 am
Newsgroups: comp.lang.lisp
From: "William James" <w_a_x_...@yahoo.com>
Date: 3 Mar 2009 07:06:44 GMT
Local: Tues, Mar 3 2009 2:06 am
Subject: Re: help with function please

david wrote:

> (defun get-four-unique-random-numbers ()
>   (loop
>      :with results = '()
>      :for alea = (random 64)
>      :while (< (length results) 4)
>      :do (pushnew alea results)
>      :finally (return results)))

Insufficient bloat.  Make it

(defun
find-and-return-four-unique-random-numbers-between-zero-and-sixty-four


    Reply to author    Forward  
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.
William James  
View profile  
(1 user)  More options Mar 3, 2:30 am
Newsgroups: comp.lang.lisp
From: "William James" <w_a_x_...@yahoo.com>
Date: 3 Mar 2009 07:30:19 GMT
Local: Tues, Mar 3 2009 2:30 am
Subject: Re: help with function please

find-and-return-four-unique-random-numbers-between-zero-and-sixty-four-
inclusive-and-exclusive-respectively

    Reply to author    Forward  
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.
Kojak  
View profile  
 More options Mar 3, 2:41 am
Newsgroups: comp.lang.lisp
From: Kojak <nntp...@janville.Borg.invalid>
Date: Tue, 3 Mar 2009 08:41:57 +0100
Local: Tues, Mar 3 2009 2:41 am
Subject: Re: help with function please
Le 3 Mar 2009 07:30:19 GMT,
William James a écrit :

> find-and-return-four-unique-random-numbers-between-zero-and-sixty-four-
> inclusive-and-exclusive-respectively

Be nice with your computer...

    find-and-return-four-unique-random-numbers-between-zero-and-
    sixty-four-inclusive-and-exclusive-respectively-PLEASE

--
Jacques.


    Reply to author    Forward  
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.
Kenneth Tilton  
View profile  
 More options Mar 3, 3:07 am
Newsgroups: comp.lang.lisp
From: Kenneth Tilton <kentil...@gmail.com>
Date: Tue, 03 Mar 2009 03:07:55 -0500
Local: Tues, Mar 3 2009 3:07 am
Subject: Re: help with function please

William James wrote:
> david wrote:

>> (defun get-four-unique-random-numbers ()
>>   (loop
>>      :with results = '()
>>      :for alea = (random 64)
>>      :while (< (length results) 4)
>>      :do (pushnew alea results)
>>      :finally (return results)))

> Insufficient bloat.  Make it

> (defun
> find-and-return-four-unique-random-numbers-between-zero-and-sixty-four

where's your damn homework, punk? are you saying Ruby cannot scale to a
25-word spec?

This must be terribly embarrassing for you. Look on the bright side:
imagine if I had posted something non-trivial!


    Reply to author    Forward  
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.
Marco Antoniotti  
View profile  
 More options Mar 3, 4:14 am
Newsgroups: comp.lang.lisp
From: Marco Antoniotti <marc...@gmail.com>
Date: Tue, 3 Mar 2009 01:14:19 -0800 (PST)
Local: Tues, Mar 3 2009 4:14 am
Subject: Re: help with function please
On Mar 3, 8:41 am, Kojak <nntp...@janville.Borg.invalid> wrote:

> Le 3 Mar 2009 07:30:19 GMT,
> William James a écrit :

> > find-and-return-four-unique-random-numbers-between-zero-and-sixty-four-
> > inclusive-and-exclusive-respectively

> Be nice with your computer...

>     find-and-return-four-unique-random-numbers-between-zero-and-
>     sixty-four-inclusive-and-exclusive-respectively-PLEASE

The Ruby Guy has not discovered Intercal yet.  Hence his
impoliteness :)

Cheers
--
Marco


    Reply to author    Forward  
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.
david  
View profile  
 More options Mar 3, 3:41 pm
Newsgroups: comp.lang.lisp
From: david <not...@gmail.com>
Date: Tue, 3 Mar 2009 12:41:04 -0800 (PST)
Local: Tues, Mar 3 2009 3:41 pm
Subject: Re: help with function please
On Mar 3, 1:30 am, "William James" <w_a_x_...@yahoo.com> wrote:
> William James wrote:

 > find-and-return-four-unique-random-numbers-between-zero-and-sixty-
four-

> inclusive-and-exclusive-respectively

when i program in common lisp i feel like i'm skiing down
a frozen mountain, the icy wind blowing in my face, as i eat
a peppermint patty sandwiched between two more peppermint patties.
can ruby make me feel like that?

thanks, david


    Reply to author    Forward  
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 »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google