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
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
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
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!
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.
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
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