From: david
Subject: help with function please
Date: 
Message-ID: <641877e5-6ee6-446a-bb2a-0c9d6ce83e18@t3g2000yqa.googlegroups.com>
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)))))

From: david
Subject: Re: help with function please
Date: 
Message-ID: <4288ee6d-1ad1-45dd-bb38-4bfd2b52366e@41g2000yqf.googlegroups.com>
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
From: Thomas A. Russ
Subject: Re: help with function please
Date: 
Message-ID: <ymiprgzlpt4.fsf@blackcat.isi.edu>
david <······@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
From: david
Subject: Re: help with function please
Date: 
Message-ID: <ce3d00dd-7d59-4b2c-9df7-e4573687bc7c@v39g2000yqm.googlegroups.com>
also i think i see problem.
two different types of wk and bk.
but i have to go to work.
later lispers.
From: Thomas A. Russ
Subject: Re: help with function please
Date: 
Message-ID: <ymitz6blpyl.fsf@blackcat.isi.edu>
david <······@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
From: William James
Subject: Re: help with function please
Date: 
Message-ID: <goiku402gir@enews5.newsguy.com>
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
From: Kenneth Tilton
Subject: Re: help with function please
Date: 
Message-ID: <49ace554$0$5902$607ed4bc@cv.net>
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!
From: William James
Subject: Re: help with function please
Date: 
Message-ID: <goimab02h72@enews5.newsguy.com>
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

find-and-return-four-unique-random-numbers-between-zero-and-sixty-four-
inclusive-and-exclusive-respectively
From: Kojak
Subject: Re: help with function please
Date: 
Message-ID: <20090303084157.4addd0df@thor.janville.org>
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.
From: Marco Antoniotti
Subject: Re: help with function please
Date: 
Message-ID: <a4bd2c94-e9de-44f1-9eac-e35018233a3d@j8g2000yql.googlegroups.com>
On Mar 3, 8:41 am, Kojak <·······@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
From: david
Subject: Re: help with function please
Date: 
Message-ID: <015d6d33-723e-46f2-b156-9ca474594690@v6g2000vbb.googlegroups.com>
On Mar 3, 1:30 am, "William James" <·········@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