From: Marco Baringer
Subject: [ANN] cl-quiz
Date: 
Message-ID: <m2r73gackc.fsf@bese.it>
http://common-lisp.net/project/quiz/

Quiz #1 has just been posted:

http://common-lisp.net/pipermail/quiz/2006-April/000002.html

enjoy,
-- 
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
	-Leonard Cohen

From: Ken Tilton
Subject: Re: [ANN] cl-quiz
Date: 
Message-ID: <8BJ4g.3$pP6.0@fe12.lga>
Marco Baringer wrote:
> http://common-lisp.net/project/quiz/
> 
> Quiz #1 has just been posted:
> 
> http://common-lisp.net/pipermail/quiz/2006-April/000002.html
> 
> enjoy,

Nice!

ken

-- 
Cells: http://common-lisp.net/project/cells/

"Have you ever been in a relationship?"
    Attorney for Mary Winkler, confessed killer of her
    minister husband, when asked if the couple had
    marital problems.
From: Tel A.
Subject: Re: cl-quiz
Date: 
Message-ID: <1146349850.663100.314870@y43g2000cwc.googlegroups.com>
A question in pertinance to the quiz:

How could one write a format directive something to the effect of

;wrong
(format nil "~r ~a~:p" 10 "apricot")
=> "10 apricots"

(format nil "~r ~a~:p" 1 "apricot")
=> "1 apricot"

I would like it to take two arguments, print the first one as a real
then print the second one, a string, with correct pluralization as per
the first argument.

Anyone done this before?
From: Geoffrey Summerhayes
Subject: Re: cl-quiz
Date: 
Message-ID: <viV4g.2850$1V4.224293@news20.bellglobal.com>
"Tel A." <············@gmail.com> wrote in message ·····························@y43g2000cwc.googlegroups.com...
>A question in pertinance to the quiz:
>
> How could one write a format directive something to the effect of
>
> ;wrong
> (format nil "~r ~a~:p" 10 "apricot")
> => "10 apricots"
>
> (format nil "~r ~a~:p" 1 "apricot")
> => "1 apricot"
>
> I would like it to take two arguments, print the first one as a real
> then print the second one, a string, with correct pluralization as per
> the first argument.
>
> Anyone done this before?

(format nil "~r ~a~:2*~P" 1 "apricot")

---
Geoff
From: Ari Johnson
Subject: Re: cl-quiz
Date: 
Message-ID: <m28xpn4sae.fsf@hermes.theari.com>
"Geoffrey Summerhayes" <·······@NhOoStPmAaMil.com> writes:

> (format nil "~r ~a~:2*~P" 1 "apricot")

(format nil "~r ~a~2:*~P of beer on the wall" 99 "bottle")

Transpose the 2 and colon.  Of course, #'format doesn't seem to be
smart enough to talk about puppies or children. ;)
From: Pascal Bourguignon
Subject: Re: cl-quiz
Date: 
Message-ID: <87bquj63e0.fsf@thalassa.informatimago.com>
Ari Johnson <················@gmail.com> writes:
> "Geoffrey Summerhayes" <·······@NhOoStPmAaMil.com> writes:
>
>> (format nil "~r ~a~:2*~P" 1 "apricot")
>
> (format nil "~r ~a~2:*~P of beer on the wall" 99 "bottle")
>
> Transpose the 2 and colon.  Of course, #'format doesn't seem to be
> smart enough to talk about puppies or children. ;)

Something can be done:

(dotimes (i 5)
  (format t "~D child~:*~[ren~;~:;ren~] & ~:*~D pupp~:*~[ies~;y~:;ies~]~%" i))

0 children & 0 puppies
1 child & 1 puppy
2 children & 2 puppies
3 children & 3 puppies
4 children & 4 puppies

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush
From: Marcin 'Qrczak' Kowalczyk
Subject: Re: cl-quiz
Date: 
Message-ID: <87bqufnldg.fsf@qrnik.zagroda>
Pascal Bourguignon <···@informatimago.com> writes:

> (dotimes (i 5)
>   (format t "~D child~:*~[ren~;~:;ren~] & ~:*~D pupp~:*~[ies~;y~:;ies~]~%" i))

What about Polish? :-)

 0 szczeniak�w
 1 szczeniak
 2 szczeniaki
 3 szczeniaki
 4 szczeniaki
 5 szczeniak�w
 6 szczeniak�w
 7 szczeniak�w
 8 szczeniak�w
 9 szczeniak�w
10 szczeniak�w
11 szczeniak�w
12 szczeniak�w
13 szczeniak�w
14 szczeniak�w
15 szczeniak�w
16 szczeniak�w
17 szczeniak�w
18 szczeniak�w
19 szczeniak�w
20 szczeniak�w
21 szczeniak�w
22 szczeniaki
23 szczeniaki
24 szczeniaki
25 szczeniak�w
26 szczeniak�w
...
(a form for 1, a form for numbers ending in 2,3,4 except those ending
in 12,13,14, and a form for others)

-- 
   __("<         Marcin Kowalczyk
   \__/       ······@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/
From: Pascal Bourguignon
Subject: Re: cl-quiz
Date: 
Message-ID: <87slnqq21u.fsf@thalassa.informatimago.com>
Marcin 'Qrczak' Kowalczyk <······@knm.org.pl> writes:

> Pascal Bourguignon <···@informatimago.com> writes:
>
>> (dotimes (i 5)
>>   (format t "~D child~:*~[ren~;~:;ren~] & ~:*~D pupp~:*~[ies~;y~:;ies~]~%" i))
>
> What about Polish? :-)
>
>  0 szczeniak�w
>  1 szczeniak
>  2 szczeniaki
>  3 szczeniaki
>  4 szczeniaki
>  5 szczeniak�w
>  6 szczeniak�w
>  7 szczeniak�w
>  8 szczeniak�w
>  9 szczeniak�w
> 10 szczeniak�w
> 11 szczeniak�w
> 12 szczeniak�w
> 13 szczeniak�w
> 14 szczeniak�w
> 15 szczeniak�w
> 16 szczeniak�w
> 17 szczeniak�w
> 18 szczeniak�w
> 19 szczeniak�w
> 20 szczeniak�w
> 21 szczeniak�w
> 22 szczeniaki
> 23 szczeniaki
> 24 szczeniaki
> 25 szczeniak�w
> 26 szczeniak�w
> ...
> (a form for 1, a form for numbers ending in 2,3,4 except those ending
> in 12,13,14, and a form for others)


(defun polish-number-declination (stream argument colon at &rest parameters)
    (declare (ignore colon at parameters))
    (cond
       ((= 1 argument))
       ((<= 1 (mod argument 10) 3) (princ "i" stream))
       (t                          (princ "�w" stream))))

You could for example use :, @ or a numerical parameter to add
different forms (masculin/feminin, etc).

(dotimes (i 40)
  (format t "~D ~A~2:*~/polish-number-declination/~%" i "szceniak"))

0 szceniak�w
1 szceniak
2 szceniaki
3 szceniaki
4 szceniak�w
5 szceniak�w
6 szceniak�w
7 szceniak�w
8 szceniak�w
9 szceniak�w
10 szceniak�w
11 szceniaki
12 szceniaki
13 szceniaki
14 szceniak�w
15 szceniak�w
16 szceniak�w
17 szceniak�w
18 szceniak�w
19 szceniak�w
20 szceniak�w
21 szceniaki
22 szceniaki
23 szceniaki
24 szceniak�w
25 szceniak�w
26 szceniak�w
27 szceniak�w
28 szceniak�w
29 szceniak�w
30 szceniak�w
31 szceniaki
32 szceniaki
33 szceniaki
34 szceniak�w
35 szceniak�w
36 szceniak�w
37 szceniak�w
38 szceniak�w
39 szceniak�w
NIL


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"I have challenged the entire quality assurance team to a Bat-Leth
contest.  They will not concern us again."
From: Timofei Shatrov
Subject: Re: cl-quiz
Date: 
Message-ID: <4459aef5.4326140@news.readfreenews.net>
On Wed, 03 May 2006 22:35:41 +0200, Pascal Bourguignon
<···@informatimago.com> tried to confuse everyone with this message:

>Marcin 'Qrczak' Kowalczyk <······@knm.org.pl> writes:
>
>> Pascal Bourguignon <···@informatimago.com> writes:
>>
>>> (dotimes (i 5)
>>>   (format t "~D child~:*~[ren~;~:;ren~] & ~:*~D pupp~:*~[ies~;y~:;ies~]~%" i))
>>
>> What about Polish? :-)
>>
>>  0 szczeniak�w
>>  1 szczeniak
>>  2 szczeniaki
>>  3 szczeniaki
>>  4 szczeniaki
>>  5 szczeniak�w
>>  6 szczeniak�w
>>  7 szczeniak�w
>>  8 szczeniak�w
>>  9 szczeniak�w
>> 10 szczeniak�w
>> 11 szczeniak�w
>> 12 szczeniak�w
>> 13 szczeniak�w
>> 14 szczeniak�w
>> 15 szczeniak�w
>> ...
>> (a form for 1, a form for numbers ending in 2,3,4 except those ending
>> in 12,13,14, and a form for others)
>

>0 szceniak�w
>1 szceniak
>2 szceniaki
>3 szceniaki
>4 szceniak�w
>5 szceniak�w
>6 szceniak�w
>7 szceniak�w
>8 szceniak�w
>9 szceniak�w
>10 szceniak�w
>11 szceniaki
>12 szceniaki
>13 szceniaki
>14 szceniak�w
>15 szceniak�w

I'm afraid you got it quite wrong :)

Should be:

(defun polish-number-declination (stream argument colon at &rest
parameters)
    (declare (ignore colon at parameters))
    (cond
       ((= 1 (mod argument 100)))
       ((and (<= 2 (mod argument 10) 4) 
             (not (<= 10 (mod argument 100) 20))
                     (princ "i" stream))
       (t                          (princ "�w" stream))))

I also suspect that different words have different endings depending on
gender and other stuff.

-- 
|WAR HAS NEVER SOLVED ANYTHING|,----- Timofei Shatrov aka Grue---------.
|(except for ending slavery,  ||mail: grue at mail.ru ================ |
|   fascism and communism)    ||============= http://grue3.tripod.com  |
|...and Saddam's dictatorship |`----------------------------------[4*72]
From: Pascal Bourguignon
Subject: Re: cl-quiz
Date: 
Message-ID: <87wtd215qq.fsf@thalassa.informatimago.com>
····@mail.ru (Timofei Shatrov) writes:

> On Wed, 03 May 2006 22:35:41 +0200, Pascal Bourguignon
> <···@informatimago.com> tried to confuse everyone with this message:
>
>>Marcin 'Qrczak' Kowalczyk <······@knm.org.pl> writes:
>>> What about Polish? :-)
>>>
>>>  0 szczeniak�w
>>>  1 szczeniak
>>>  2 szczeniaki
>>>  3 szczeniaki
>>>  4 szczeniaki
>>>  5 szczeniak�w
>>> ...
>>> (a form for 1, a form for numbers ending in 2,3,4 except those ending
>>> in 12,13,14, and a form for others)
>>
>
>>0 szceniak�w
>>1 szceniak
>>2 szceniaki
>>3 szceniaki
>>4 szceniak�w
>
> I'm afraid you got it quite wrong :)

Oops, yes, I shifted it down by 1...

> Should be:
>
> (defun polish-number-declination (stream argument colon at &rest
> parameters)
>     (declare (ignore colon at parameters))
>     (cond
>        ((= 1 (mod argument 100)))
>        ((and (<= 2 (mod argument 10) 4) 
>              (not (<= 10 (mod argument 100) 20))
>                      (princ "i" stream))
>        (t                          (princ "�w" stream))))
>
> I also suspect that different words have different endings depending on
> gender and other stuff.

Yes, that's why I proposed to extend it to convey some meaning to
colon/at or parameters.  Unfortunately, my mother never taught me
Polish :-(

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.
From: Marcin 'Qrczak' Kowalczyk
Subject: Re: cl-quiz
Date: 
Message-ID: <87d5essbt0.fsf@qrnik.zagroda>
····@mail.ru (Timofei Shatrov) writes:

> I also suspect that different words have different endings depending
> on gender and other stuff.

Right, and for this reason the format should list all endings
explicitly.

Here is how GNU gettext does it, and what other languages need:
http://www.gnu.org/software/gettext/manual/html_node/gettext_150.html

-- 
   __("<         Marcin Kowalczyk
   \__/       ······@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/
From: David Sletten
Subject: Re: cl-quiz
Date: 
Message-ID: <sZ%4g.5260$Nk3.3222@tornado.socal.rr.com>
Ari Johnson wrote:

> "Geoffrey Summerhayes" <·······@NhOoStPmAaMil.com> writes:
> 
> 
>>(format nil "~r ~a~:2*~P" 1 "apricot")
> 
> 
> (format nil "~r ~a~2:*~P of beer on the wall" 99 "bottle")
> 
> Transpose the 2 and colon.  Of course, #'format doesn't seem to be
> smart enough to talk about puppies or children. ;)

Well, yes and no:
(format nil "~r ·······@p of beer on the wall" 99 "pupp") => 
"ninety-nine puppies of beer on the wall"

(format nil "~r ·······@p of beer on the wall" 1 "fl") => "one fly of 
beer on the wall"

Whatever that means... :)

Aloha,
David Sletten
From: Geoffrey Summerhayes
Subject: Re: cl-quiz
Date: 
Message-ID: <ATw5g.692$VV2.45386@news20.bellglobal.com>
"Ari Johnson" <················@gmail.com> wrote in message ···················@hermes.theari.com...
> "Geoffrey Summerhayes" <·······@NhOoStPmAaMil.com> writes:
>
>> (format nil "~r ~a~:2*~P" 1 "apricot")
>
> (format nil "~r ~a~2:*~P of beer on the wall" 99 "bottle")
>
<snip>

Bah! Good catch. Serves me right for posting during a
disrupted sleep cycle.

--
Geoff
From: Ari Johnson
Subject: Re: cl-quiz
Date: 
Message-ID: <m2slnt2n30.fsf@hermes.theari.com>
"Geoffrey Summerhayes" <·······@NhOoStPmAaMil.com> writes:

> "Ari Johnson" <················@gmail.com> wrote...
>> "Geoffrey Summerhayes" <·······@NhOoStPmAaMil.com> writes:
>>
>>> (format nil "~r ~a~:2*~P" 1 "apricot")
>>
>> (format nil "~r ~a~2:*~P of beer on the wall" 99 "bottle")
>>
> <snip>
>
> Bah! Good catch. Serves me right for posting during a
> disrupted sleep cycle.

I confess that it had nothing to do with knowledge and everything to
do with randomly transposing characters until #'format decided to work
for me. :)
From: David Sletten
Subject: Re: cl-quiz
Date: 
Message-ID: <_mV4g.3642$yM.2873@tornado.socal.rr.com>
Tel A. wrote:

> A question in pertinance to the quiz:
> 
> How could one write a format directive something to the effect of
> 
> ;wrong
> (format nil "~r ~a~:p" 10 "apricot")
> => "10 apricots"
> 
> (format nil "~r ~a~:p" 1 "apricot")
> => "1 apricot"
> 
> I would like it to take two arguments, print the first one as a real
> then print the second one, a string, with correct pluralization as per
> the first argument.
> 
> Anyone done this before?
> 

There's so much magic in FORMAT that it takes a while to get familiar 
with it all:
http://www.lispworks.com/documentation/HyperSpec/Body/22_cga.htm

You can use ~n:* to back up n arguments, with 1 the default:
(format nil "~r ~a~:*~:p" 10 "apricot") => "ten apricots"

But based on your description you probably want ~D rather than ~R:
(format nil "~d ~a~:*~:p" 1 "apricot") => "1 apricot"

Unless you actually meant "float" when you wrote "real":
(format nil "~f ~a~:*~:p" 1 "apricot") => "1.0 apricot"

(Remember that you're not really "printing" anything when you use NIL as 
the first argument to FORMAT.)

Aloha,
David Sletten