From ... Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!fr.usenet-edu.net!usenet-edu.net!ciril.fr!news.ujf-grenoble.fr!univ-lyon1.fr!nmaster.kpnqwest.net!nreader1.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: EQ and FIXNUMS References: <3BAEF9CF.8AD3D2CB@eurocom.od.ua> Mail-Copies-To: never From: Erik Naggum Message-ID: <3210317497232745@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 51 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 24 Sep 2001 10:51:37 GMT X-Complaints-To: newsmaster@Norway.EU.net X-Trace: nreader1.kpnqwest.net 1001328697 193.90.206.143 (Mon, 24 Sep 2001 12:51:37 MET DST) NNTP-Posting-Date: Mon, 24 Sep 2001 12:51:37 MET DST Xref: archiver1.google.com comp.lang.lisp:16868 * "Vladimir V. Zolotych" > I've accustom myself to think of EQ as doing pointer comparison. Once > interned a particular symbol remains so symbols that print the same > should be EQed. What take place with numbers and chars in implementation > where EQ works for them ? Does it mean that all objects representing > fixnums, for example, have "standard" places in Lisp ? You can think of eq as a one-instruction machine-word comparison. For this explanation to be adequate, you need to know how Lisp represents pointers to its objects _and_ fixnums and characters in the same machine word. Let me take Allegro CL as an example (inspect #\a) character #\a [#x0000030e] char-code #x0061 (inspect #x0061) fixnum 97 [#x00000184] The binary representation reveals the internals (write #x30e :base 2) 1100001110 (write #x184 :base 2) 110000100 (write #x61 :base 2) 1100001 We see that a character has three extra bits (110) and fixnums two (00), and these bits work as type bits. (Actually, fixnums also have three, but the least significant bit doubles as a type bit, so both 100 and 000 identify a fixnum.) We notice that on 32-bit hardware, no pointers can have non-zero values in the least two significant bits, so they are free for other uses, and the hardware support for adding small integer value sto pointers at deferencing time, coupled with good hardware support for unaligned access traps, we get type-checking for free, too. Thus we see that eq can use machine-word comparison instructions directly. If you wish, you can consider the machine-word representation of fixnums and characters as fixed, virtual addresses of constant objects. eql, on the other hand, will have to check for two bignums and compare them numerically. /// -- Why did that stupid George W. Bush turn to Christian fundamentalism to fight Islamic fundamentalism? Why use terms like "crusade", which only invokes fear of a repetition of that disgraceful period of Christianity with its _sustained_ terrorist attacks on Islam? He is _such_ an idiot.