Re: Two questions about eq



Scott Burson <FSet.SLB@xxxxxxxxx> writes:

On Mar 31, 8:49 am, Spiros Bousbouras <spi...@xxxxxxxxx> wrote:
1) The HS says that
(eq (cons 'a 'b) (cons 'a 'b))
always returns false but
(eq '(a . b) '(a . b))
might be true. Why is this ?

Because the compiler is allowed to select a canonical instance for
quoted constants (since you're not supposed to modify them). So, the
compiler could use the same cons for both occurrences of the quoted
dotted pair.

Explicitly, you can implement ' reader macro as:

(set-macro-character #\'
(let ((literal-stuff (make-hash-table :test (function equal))))
(lambda (stream quote)
(declare (ignore quote))
(let ((new-literal (read stream nil t)))
(or (gethash new-literal literal-stuff)
(setf (gethash new-literal literal-stuff) new-literal)))))
nil *readtable*)

2) Under what (realistic) circumstances might
(eq 1 1) be false ?

For example, imagine you're implementing CL over perl. I mean,
perhaps you have to write perl script, but you just cannot stand perl
syntax, so you decide to implement a CL over perl to be able to
produce perl scripts... Ok then, in perl data is not typed. 1 ==
"1". When you have 1 in perl you cannot tell if it's a string, an
integer, a float or what. So you implement all lisp objects as a perl
hash, with a type slot and a value slot. When you write (eq 1 1),
it's translated to:
lisp_eq({type=>integer,value=>1},{type=>integer,value=>1});
and of course, the two hash tables are not 'eq'.

Otherwise, very few are the cl implementations that have not (eq 1 1),
but most of them have (not (eq (1+ most-positive-fixnum)
(1+ most-positive-fixnum))).

Realistically, none, but use `eql' anyway.

-- Scott

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

"What is this talk of "release"? Klingons do not make software
"releases". Our software "escapes" leaving a bloody trail of
designers and quality assurance people in its wake."
.



Relevant Pages

  • Re: Fwd: DBD::Informix A configuration failure
    ... Perl doesn't think your compiler handles prototypes. ... Testing whether your Informix test environment will work... ... >> problems with the test program, you will need to revisit this ...
    (perl.dbi.users)
  • Re: ANNOUNCE: DBD:Oracle 1.18
    ... Well a warning in one compiler is better than and error in an other so I ... This might be a problem more with the older oracle OCI in your client. ... perl -Mblib t/26exe_array.t ...
    (perl.dbi.users)
  • Re: Compiler and an interpreter
    ... >>> error.Can anybody please tell me how the compiler and interpreter will ... Some small unit of the language is an acceptable input. ... > Perl does not to my knowledge in any way require the reading of the ...
    (comp.programming)
  • Re: Redefinition of target errors
    ... compiler instead of the Borland compiler. ... I can't remember if you said your Perl was activestate. ... to find a link or a way to get dmake for Borland. ... The last time I tried to compile a perl module written in C for Windows it was a real PITA. ...
    (perl.dbi.users)
  • Re: Fwd: DBD::Informix A configuration failure
    ... Your previous subject line was 'problem install DBD Informix'. ... > perl Makefile.PL ... > Configuring IBM Informix Database Driver for Perl Version 2003.04 ... Perl doesn't think your compiler handles prototypes. ...
    (perl.dbi.users)