Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[ANN] cl-quiz

5 views
Skip to first unread message

Marco Baringer

unread,
Apr 29, 2006, 6:41:39 AM4/29/06
to

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

Ken Tilton

unread,
Apr 29, 2006, 9:10:29 AM4/29/06
to

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.

Tel A.

unread,
Apr 29, 2006, 6:30:50 PM4/29/06
to
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?

David Sletten

unread,
Apr 29, 2006, 10:34:34 PM4/29/06
to
Tel A. wrote:

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

Geoffrey Summerhayes

unread,
Apr 29, 2006, 10:29:41 PM4/29/06
to

"Tel A." <abraha...@gmail.com> wrote in message news:1146349850.6...@y43g2000cwc.googlegroups.com...

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

---
Geoff


Ari Johnson

unread,
Apr 30, 2006, 12:10:49 AM4/30/06
to
"Geoffrey Summerhayes" <sum...@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. ;)

Pascal Bourguignon

unread,
Apr 30, 2006, 1:25:43 AM4/30/06
to

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

David Sletten

unread,
Apr 30, 2006, 6:05:12 AM4/30/06
to
Ari Johnson wrote:

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

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

Whatever that means... :)

Aloha,
David Sletten

Geoffrey Summerhayes

unread,
May 1, 2006, 7:31:46 PM5/1/06
to

"Ari Johnson" <iamthear...@gmail.com> wrote in message news:m28xpn4...@hermes.theari.com...

> "Geoffrey Summerhayes" <sum...@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

Ari Johnson

unread,
May 1, 2006, 10:10:43 PM5/1/06
to
"Geoffrey Summerhayes" <sum...@NhOoStPmAaMil.com> writes:

> "Ari Johnson" <iamthear...@gmail.com> wrote...


>> "Geoffrey Summerhayes" <sum...@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. :)

Marcin 'Qrczak' Kowalczyk

unread,
May 3, 2006, 12:06:35 PM5/3/06
to
Pascal Bourguignon <p...@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
\__/ qrc...@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/

Pascal Bourguignon

unread,
May 3, 2006, 4:35:41 PM5/3/06
to


(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."

Timofei Shatrov

unread,
May 4, 2006, 3:44:03 AM5/4/06
to
On Wed, 03 May 2006 22:35:41 +0200, Pascal Bourguignon
<p...@informatimago.com> tried to confuse everyone with this message:

>Marcin 'Qrczak' Kowalczyk <qrc...@knm.org.pl> writes:
>
>> Pascal Bourguignon <p...@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]

Pascal Bourguignon

unread,
May 4, 2006, 5:47:25 AM5/4/06
to
gr...@mail.ru (Timofei Shatrov) writes:

> On Wed, 03 May 2006 22:35:41 +0200, Pascal Bourguignon
> <p...@informatimago.com> tried to confuse everyone with this message:
>
>>Marcin 'Qrczak' Kowalczyk <qrc...@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.

Marcin 'Qrczak' Kowalczyk

unread,
May 5, 2006, 11:58:51 AM5/5/06
to
gr...@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

0 new messages