From: John Thingstad
Subject: First entries in games book available.
Date: 
Message-ID: <opr6717k1nxfnb1n@news.chello.no>
http://home.chello.no/~jthing now contains the source for hangman and 
russian roulette.
There is altso a simple forword.
The hangman dictionary you can generate yourself.
The syntax is simple just one line per word.
To generate a index on the file run genindex on it first.
(the index and dictionary are actually in the directory.
try loading hangman.dict and hangman.index)

Feel free to express any comments.
I expect to add startrek, mastermind and othello to the list soon

Have fun!
-- 
Sender med M2, Operas revolusjonerende e-postprogram: http://www.opera.com/

From: John Thingstad
Subject: Re: First entries in games book available.
Date: 
Message-ID: <opr68ycwfjxfnb1n@news.chello.no>
Just added startrek, mastermind and othello as promiced.

P� Thu, 29 Apr 2004 15:22:22 +0100, skrev John Thingstad 
<··············@chello.no>:

>
> http://home.chello.no/~jthing now contains the source for hangman and 
> russian roulette.
> There is altso a simple forword.
> The hangman dictionary you can generate yourself.
> The syntax is simple just one line per word.
> To generate a index on the file run genindex on it first.
> (the index and dictionary are actually in the directory.
> try loading hangman.dict and hangman.index)
>
> Feel free to express any comments.
> I expect to add startrek, mastermind and othello to the list soon
>
> Have fun!



-- 
Sender med M2, Operas revolusjonerende e-postprogram: http://www.opera.com/
From: Peter Lewerin
Subject: Re: First entries in games book available.
Date: 
Message-ID: <b72f3640.0404301218.679289ac@posting.google.com>
John Thingstad <··············@chello.no> wrote 

> > http://home.chello.no/~jthing now contains the source for hangman and 
> > russian roulette.

Seems very nice.  I had a look at "Russian roulette", and it seems to
me that it would be neater this way:

(defun get-integer (&optional (string "select chamber: "))
  (write-string string)
  (force-output)
  (clear-input)
  (ignore-errors (parse-integer (read-line))))

(defun get-selection (&key (low 1) (high 6) (message "~&Type a number
between ~D and ~D.~%"))
  (do ((sel (get-integer) (get-integer)))
      ((and (numberp sel) (>= sel low) (<= sel high)) sel)
    (format *standard-output* message low high)))

(defun russian-roulette ()
  "Plays the game of russian roulette"
  (write-line "This is the game of russian roulette.")
  (do ((dollars 100 (incf dollars 100))
       (barrel (+ (random 6) 1) (+ (random 6) 1))
       (chamber (get-selection) (get-selection)))
      ((= barrel chamber) (format *standard-output* "~&Bang! You're
dead..~%"))
    (format *standard-output* "~&PHUH! You have a ~R dollars
credit.~%" dollars)
    (unless (y-or-n-p "Play again? ") (return))))
From: John Thingstad
Subject: Re: First entries in games book available.
Date: 
Message-ID: <opr7an9xwuxfnb1n@news.chello.no>
Not so sure about this one.
I still have problems reading do loops.
So much the worse for a beginner.
I personally think that forthe first dive into a language the first 
impression
is important. If it takes to much mental effort to 'translate' the code
into meaning I would probably dimiss the language.
Thogh you are right that the code can be improved it has the
'advantage'(?) to be one of the first programs i wrote in comon Lisp.
Hence it reflectes what I mastered first and a style I found the most
natural.

John

P� 30 Apr 2004 13:18:46 -0700, skrev Peter Lewerin 
<·············@swipnet.se>:

> John Thingstad <··············@chello.no> wrote
>
>> > http://home.chello.no/~jthing now contains the source for hangman and
>> > russian roulette.
>
> Seems very nice.  I had a look at "Russian roulette", and it seems to
> me that it would be neater this way:
>
> (defun get-integer (&optional (string "select chamber: "))
>   (write-string string)
>   (force-output)
>   (clear-input)
>   (ignore-errors (parse-integer (read-line))))
>
> (defun get-selection (&key (low 1) (high 6) (message "~&Type a number
> between ~D and ~D.~%"))
>   (do ((sel (get-integer) (get-integer)))
>       ((and (numberp sel) (>= sel low) (<= sel high)) sel)
>     (format *standard-output* message low high)))
>
> (defun russian-roulette ()
>   "Plays the game of russian roulette"
>   (write-line "This is the game of russian roulette.")
>   (do ((dollars 100 (incf dollars 100))
>        (barrel (+ (random 6) 1) (+ (random 6) 1))
>        (chamber (get-selection) (get-selection)))
>       ((= barrel chamber) (format *standard-output* "~&Bang! You're
> dead..~%"))
>     (format *standard-output* "~&PHUH! You have a ~R dollars
> credit.~%" dollars)
>     (unless (y-or-n-p "Play again? ") (return))))



-- 
Sender med M2, Operas revolusjonerende e-postprogram: http://www.opera.com/
From: Peter Lewerin
Subject: Re: First entries in games book available.
Date: 
Message-ID: <b72f3640.0405011306.5a8c0c83@posting.google.com>
John Thingstad <··············@chello.no> wrote

> Not so sure about this one.
> I still have problems reading do loops.
> So much the worse for a beginner.

Not for every beginner.  I regard do as just an extended let.  I find
loop a lot harder to get right.

How about this, then:

;;; Russian Roulette

(defun get-integer (&optional (string "select chamber: "))
  (write-string string)
  (force-output)
  (clear-input)
  (ignore-errors (parse-integer (read-line))))

(defun get-selection (&key (low 1) (high 6) (message "~&Type a number
between ~D and ~D.~%"))
  (loop for sel = (get-integer)
	until (and (numberp sel) (>= sel low) (<= sel high))
	do
	(format *standard-output* message low high)
	finally (return sel)))

(defun play ()
  "Plays the game of russian roulette"
  (write-line "This is the game of russian roulette.")
  (loop for dollars from 100 by 100
	and barrel = (+ (random 6) 1)
	and chamber = (get-selection)
	until (= barrel chamber)
	do 
	(format *standard-output* "~&PHUH! You have a ~R dollars credit.~%"
dollars)
	(unless (y-or-n-p "Play again? ") (return))
	finally (format *standard-output* "~&Bang! You're dead..~%")))
From: David Steuber
Subject: Re: First entries in games book available.
Date: 
Message-ID: <87zn8r8vy5.fsf@david-steuber.com>
John Thingstad <··············@chello.no> writes:

> Thogh you are right that the code can be improved it has the
> 'advantage'(?) to be one of the first programs i wrote in comon
> Lisp.  Hence it reflectes what I mastered first and a style I found
> the most natural.

I started with BASIC and then moved onto Fortran 77, Pascal, and
C/C++.  I've also done some work in Perl.

Once I got used to C/C++, that became my most natural way to think.  I
tended to think imperatively in C terms.  Perl helped me start to
break away from that style of thinking, but C still dominates.

To me, this has been a handicap with learning Lisp.

The functional style that Paul Graham and others write about looks
like it fits more naturally to Lisp than some awkward C
transliteration.  So what I've been doing is trying to put C out of my
mind.  The only real problems that seem left are related to
terminology.  Maybe its me misreading, but I seem to come across uses
of words that are C like in some places and Lisp like in others.  Like
the word dynamic when it describes a variable.

I'm sure I will over come this.  For one thing, the CLHS has a
glossary.  Although reading dictonaries is not exactly an exciting
thing to do, it helps to know the lingo.  People who spent twenty
years programming Lisp do not talk the same way as people with twenty
years of C behind them.

While Lisp is programmable to whatever style you prefer, according to
the marketing literature, the basic functional paradigm seems to be
the foundation for natural Lisp.  It may be a bit advanced for me, but
the OnLisp book is making that point much clearer than what I have
read so far.  I don't want to say I get it yet, but I think now that
reverting back to C think is already something I would not want to
do.  I think I would rather go straight down to assembler ;-)

I'm sure that writing poetry in English is different from writing
poetry in Japanese.  Unlike the Germanic languages, there is no real
common ancestor between the two, so the thinking is different.

Lisp is not Fortran.  There is no common ancestor.

-- 
I wouldn't mind the rat race so much if it wasn't for all the damn cats.