(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
> (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 ()
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:
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
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 :)
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.
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."
> 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/
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,...
In C...
#define QUESTION (0x2b | ~0x2b)
> 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 ;^)