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

To be or not to be: the way of Lisp

10 views
Skip to first unread message

Emre Sevinc

unread,
Nov 20, 2005, 9:56:23 AM11/20/05
to

Just another way to explore the meaning of life [1] using the Lisp way:

(format t "Shakespeare has given us the age-old question, \"To be or not to be?\"
Computer science has given us the answer:~%
~x | ~~~x == ~x" #x2B #x2B (ldb (byte 8 0) (logior #x2B (lognot #x2B))))


1- "How not to program in C++" by Steve Qualline, page 164.


PS: Hmm, do we need a book "How not to program in Lisp", or not?

--
Emre Sevinc

eMBA Software Developer Actively engaged in:
http:www.bilgi.edu.tr http://ileriseviye.org
http://www.bilgi.edu.tr http://fazlamesai.net
Cognitive Science Student http://cazci.com
http://www.cogsci.boun.edu.tr

verec

unread,
Nov 20, 2005, 5:22:39 PM11/20/05
to
On 2005-11-20 14:56:23 +0000, Emre Sevinc <em...@bilgi.edu.tr> said:

> (format t "Shakespeare has given us the age-old question, \"To be or
> not to be?\" Computer science has given us the answer:~%
> ~x | ~~~x == ~x" #x2B #x2B (ldb (byte 8 0) (logior #x2B (lognot #x2B))))

Stupid me! I was expecting 42!

:-)
--
JFB ()

Lars Brinkhoff

unread,
Nov 21, 2005, 6:39:17 AM11/21/05
to
Emre Sevinc <em...@bilgi.edu.tr> writes:
> Just another way to explore the meaning of life [1] using the Lisp way:
> (format t "Shakespeare has given us the age-old question,
> \"To be or not to be?\"
> Computer science has given us the answer:~%
> ~x | ~~~x == ~x"
> #x2B #x2B (ldb (byte 8 0) (logior #x2B (lognot #x2B))))

Do you mean that the book contained this Lisp snippet (which seems
unlikely but nice), or did you translate it from C++?

> 1- "How not to program in C++" by Steve Qualline, page 164.

His name appears to be Steve Oualline:

http://www.oualline.com/

Rob Warnock

unread,
Nov 21, 2005, 6:52:45 AM11/21/05
to
verec <ve...@mac.com> wrote:
+---------------

| Emre Sevinc <em...@bilgi.edu.tr> said:
| > (format t "Shakespeare has given us the age-old question, \"To be or
| > not to be?\" Computer science has given us the answer:~%
| > ~x | ~~~x == ~x" #x2B #x2B (ldb (byte 8 0) (logior #x2B (lognot #x2B))))
|
| Stupid me! I was expecting 42!
+---------------

Off by one; #x2A is the answer to "Life, the Universe, and Everything".


-Rob

-----
Rob Warnock <rp...@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607

Emre Sevinc

unread,
Nov 21, 2005, 7:54:19 AM11/21/05
to
>>>>> "verec" == verec <ve...@mac.com> writes:

verec> On 2005-11-20 14:56:23 +0000, Emre Sevinc


verec> <em...@bilgi.edu.tr> said:
>> (format t "Shakespeare has given us the age-old question, \"To
>> be or not to be?\" Computer science has given us the answer:~%
>> ~x | ~~~x == ~x" #x2B #x2B (ldb (byte 8 0) (logior #x2B (lognot
>> #x2B))))

verec> Stupid me! I was expecting 42!

That's what many of my fellow programmers (who read Douglas Adams)
said :)

Emre Sevinc

unread,
Nov 21, 2005, 8:05:50 AM11/21/05
to
>>>>> "LB" == Lars Brinkhoff <lars...@nocrew.org> writes:

LB> Emre Sevinc <em...@bilgi.edu.tr> writes:
>> Just another way to explore the meaning of life [1] using the
>> Lisp way: (format t "Shakespeare has given us the age-old
>> question, \"To be or not to be?\" Computer science has given us
>> the answer:~% ~x | ~~~x == ~x" #x2B #x2B (ldb (byte 8 0)
>> (logior #x2B (lognot #x2B))))

LB> Do you mean that the book contained this Lisp snippet (which
LB> seems unlikely but nice), or did you translate it from C++?

Neither one. The book just contained [1]:

Shakespeare has given us the age-old question, "To be or not to be?"

Computer science has given us the answer: "FF".

0x2B | ~0x2B == FF

Well, I must admit that my first reaction was to write a
short code in C and compile it with gcc. After that I tried
it with Lisp but without using (ldb (byte 8 0) ...
I couldn't get the FF result I wanted (I got -1). Finally
I came up with the code you see.

>> 1- "How not to program in C++" by Steve Qualline, page 164.

LB> His name appears to be Steve Oualline:
LB> http://www.oualline.com/

Opps, you're right, my mistake! Sorry.


1- http://books.google.com/books?hl=en&id=wgwE0dQ15xEC&pg=PA164&lpg=PA164&dq=shakespeare+Computer+science+has+given+us+the+answer&prev=http://books.google.com/books%3Fq%3Dshakespeare%2BComputer%2Bscience%2Bhas%2Bgiven%2Bus%2Bthe%2Banswer%26lr%3D%26client%3Dfirefox-a&sig=KElCnNfr6jUYieU4NIw9CcWUGQk

Emre Sevinc

unread,
Nov 21, 2005, 8:19:16 AM11/21/05
to
>>>>> "LB" == Lars Brinkhoff <lars...@nocrew.org> writes:

LB> Emre Sevinc <em...@bilgi.edu.tr> writes:
>> Just another way to explore the meaning of life [1] using the
>> Lisp way: (format t "Shakespeare has given us the age-old
>> question, \"To be or not to be?\" Computer science has given us
>> the answer:~% ~x | ~~~x == ~x" #x2B #x2B (ldb (byte 8 0)
>> (logior #x2B (lognot #x2B))))

LB> Do you mean that the book contained this Lisp snippet (which
LB> seems unlikely but nice), or did you translate it from C++?

And Oualline adds:

"Most of the time when I tell this joke to non-technical people
they just look at me strangely. Technical people tend to think
for a minute and then say, "You're right." Only one person
in about a hundred actually laughs."

Marcin 'Qrczak' Kowalczyk

unread,
Nov 21, 2005, 9:41:26 AM11/21/05
to
Emre Sevinc <em...@bilgi.edu.tr> writes:

> Shakespeare has given us the age-old question, "To be or not to be?"
> Computer science has given us the answer: "FF".
>
> 0x2B | ~0x2B == FF
>
> Well, I must admit that my first reaction was to write a
> short code in C and compile it with gcc. After that I tried
> it with Lisp but without using (ldb (byte 8 0) ...
> I couldn't get the FF result I wanted (I got -1).

Because the result *is* -1, unless you artificially take only 8 bits
of it and treat them as unsigned.

--
__("< Marcin Kowalczyk
\__/ qrc...@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/

Emre Sevinc

unread,
Nov 21, 2005, 9:54:46 AM11/21/05
to
>>>>> "MK" == Marcin 'Qrczak' Kowalczyk <qrc...@knm.org.pl> writes:

MK> Emre Sevinc <em...@bilgi.edu.tr> writes:
>> Shakespeare has given us the age-old question, "To be or not to
>> be?" Computer science has given us the answer: "FF".
>>
>> 0x2B | ~0x2B == FF
>>
>> Well, I must admit that my first reaction was to write a short
>> code in C and compile it with gcc. After that I tried it with
>> Lisp but without using (ldb (byte 8 0) ... I couldn't get the
>> FF result I wanted (I got -1).

MK> Because the result *is* -1, unless you artificially take only
MK> 8 bits of it and treat them as unsigned.

You're right, it is. The only thing is that I just couldn't
find quickly the way to treat it as an unsigned 8-bit quantity.
Wandering around CLHS or CLtL2 didn't produce any quick results
and for the first time in my life I heard of a concept called
"bit weight" (which I'm trying to understand).

BTW I believe that treating the result as -1 is THE artifical
viewpoint, a method that is used as an interpretation for
negative numbers. Unless you interpret it, it is nothing but
1s and 0s right?

I was happy that #lisp existed on irc.freenode.net ;-) Sometimes
a NII (natural intelligence interfece) to something like CLHS
is a real helper (of course I don't deny that true understanding
doesn't come from quick solutions but from detailed study of specification
and experimenting, but that's another story).

1- ...byte returns a byte specifier that indicates a byte of width size
and whose *bits have weights* 2^position + size - 1 through 2^position,...

justinhj

unread,
Nov 21, 2005, 12:05:19 PM11/21/05
to

In C...

#define QUESTION (0x2b | ~0x2b)

Raffael Cavallaro

unread,
Nov 21, 2005, 8:52:18 PM11/21/05
to
On 2005-11-21 06:52:45 -0500, rp...@rpw3.org (Rob Warnock) said:

> Off by one; #x2A is the answer to "Life, the Universe, and Everything".

CL-USER> (or #x2b (not #x2b))
43

but...

CL-USER> (logior #x2B (lognot #x2B))
-1

however, if we combine these two approaches...


CL-USER> (+ (or #x2b (not #x2b)) (logior #x2B (lognot #x2B)))
42

Coincidence? I think not ;^)

0 new messages