User Tools

A PCRE internal error occured. This might be caused by a faulty plugin


This shows you the differences between two versions of the page.

Link to this comparison view

cl:functions:eq [2019/11/11 05:00]
cl:functions:eq [2020/07/12 15:00] (current)
Line 1: Line 1:
 +====== Function EQ ======
 +  * **eq** //x y// → //​generalized-boolean//​
 +====Arguments and Values====
 +  * //x// - an //​[[CL:​Glossary:​object]]//​.
 +  * //y// - an //​[[CL:​Glossary:​object]]//​.
 +  * //​generalized-boolean//​ - a //​[[CL:​Glossary:​generalized boolean]]//​.
 +Returns //​[[CL:​Glossary:​true]]//​ if its //​[[CL:​Glossary:​arguments]]//​ are the same, identical //​[[CL:​Glossary:​object]]//;​ otherwise, returns //​[[CL:​Glossary:​false]]//​.
 +(eq 'a 'b) <​r>//​[[CL:​Glossary:​false]]//​ </r>
 +(eq 'a 'a) <​r>//​[[CL:​Glossary:​true]]//​ </r>
 +(eq 3 3) <​r>//​[[CL:​Glossary:​true]]// ​
 +//or// //​[[CL:​Glossary:​false]]//​ </r>
 +(eq 3 3.0) <​r>//​[[CL:​Glossary:​false]]//​ </r>
 +(eq 3.0 3.0) <​r>//​[[CL:​Glossary:​true]]//​
 +//or// //​[[CL:​Glossary:​false]]//​ </r>
 +(eq #c(3 -4) #c(3 -4)) <​r>//​[[CL:​Glossary:​true]]//​
 +//or// //​[[CL:​Glossary:​false]]//​ </r>
 +(eq #c(3 -4.0) #c(3 -4)) <​r>//​[[CL:​Glossary:​false]]//​ </r>
 +(eq ([[CL:​Functions:​cons]] 'a 'b) ([[CL:​Functions:​cons]] 'a 'c)) <​r>//​[[CL:​Glossary:​false]]//​ </r>
 +(eq ([[CL:​Functions:​cons]] 'a 'b) ([[CL:​Functions:​cons]] 'a 'b)) <​r>//​[[CL:​Glossary:​false]]//​ </r>
 +(eq '(a . b) '(a . b)) <​r>//​[[CL:​Glossary:​true]]//​
 +//or// //​[[CL:​Glossary:​false]]//​ </r>
 +([[CL:​Special Operators:​progn]] ([[CL:​Macros:​defparameter]] *x* ([[CL:​Functions:​cons]] 'a 'b)) (eq *x* *x*)) <​r>//​[[CL:​Glossary:​true]]//​ </r>
 +([[CL:​Special Operators:​progn]] ([[CL:​Macros:​defparameter]] *x* '(a . b)) (eq *x* *x*)) <​r>//​[[CL:​Glossary:​true]]//​ </r>
 +([[CL:​Special Operators:​progn]] ([[CL:​Special Operators:​let]] ((x ([[CL:​Functions:​cons]] 'a 'b))) (eq x x))) <​r>//​[[CL:​Glossary:​true]]//​ </r>
 +([[CL:​Special Operators:​progn]] ([[CL:​Special Operators:​let]] ((x '(a . b))) (eq x x))) <​r>//​[[CL:​Glossary:​true]]//​ </r>
 +(eq #\\A #\\A) <​r>//​[[CL:​Glossary:​true]]//​
 +//or// //​[[CL:​Glossary:​false]]//​ </r>
 +([[CL:​Special Operators:​let]] ((x "​Foo"​)) (eq x x)) <​r>//​[[CL:​Glossary:​true]]//​ </r>
 +(eq "​Foo"​ "​Foo"​) <​r>//​[[CL:​Glossary:​true]]//​
 +//or// //​[[CL:​Glossary:​false]]//​ </r>
 +(eq "​Foo"​ ([[CL:​Functions:​copy-seq]] "​Foo"​)) <​r>//​[[CL:​Glossary:​false]]//​ </r>
 +(eq "​FOO"​ "​foo"​) <​r>//​[[CL:​Glossary:​false]]//​ </r>
 +(eq "​string-seq"​ ([[CL:​Functions:​copy-seq]] "​string-seq"​)) <​r>//​[[CL:​Glossary:​false]]//​ </r>
 +([[CL:​Special Operators:​let]] ((x 5)) (eq x x)) <​r>//​[[CL:​Glossary:​true]]//​
 +//or// //​[[CL:​Glossary:​false]]//​ </r>
 +====Side Effects====
 +====Affected By====
 +====Exceptional Situations====
 +====See Also====
 +  * **[[CL:​Functions:​eql|Function EQL]]**
 +  * **[[CL:​Functions:​equal|Function EQUAL]]**
 +  * **[[CL:​Functions:​equalp|Function EQUALP]]**
 +  * **[[CL:​Functions:​math-equal|Function =]]**
 +  * {\secref\Compilation}
 +//​[[CL:​Glossary:​object|objects]]//​ that appear the same when printed are not necessarily **eq** to each other. //​[[CL:​Glossary:​Symbols]]//​ that print the same usually are **eq** to each other because of the use of the **[[CL:​Functions:​intern]]** function. However, //​[[CL:​Glossary:​numbers]]//​ with the same value need not be **eq**, and two similar //​[[CL:​Glossary:​lists]]//​ are usually not //​[[CL:​Glossary:​identical]]//​.
 +An implementation is permitted to make "​copies"​ of //​[[CL:​Glossary:​characters]]//​ and //​[[CL:​Glossary:​numbers]]//​ at any time. The effect is that Common Lisp makes no guarantee that **eq** is true even when both its arguments are "the same thing" if that thing is a //​[[CL:​Glossary:​character]]//​ or //​[[CL:​Glossary:​number]]//​.
 +Most Common Lisp //​[[CL:​Glossary:​operators]]//​ use **[[CL:​Functions:​eql]]** rather than **eq** to compare objects, or else they default to **[[CL:​Functions:​eql]]** and only use **eq** if specifically requested to do so. However, the following //​[[CL:​Glossary:​operators]]//​ are defined to use **eq** rather than **[[CL:​Functions:​eql]]** in a way that cannot be overridden by the //​[[CL:​Glossary:​code]]//​ which employs them:
 +| [[CL:​Special Operators:​catch]] ​ | [[CL:​Functions:​getf]] ​   | [[CL:​Special Operators:​throw]] |
 +| [[CL:​Functions:​get]] ​           | [[CL:​Macros:​remf]] ​      ​| ​                               |
 +| [[CL:​Functions:​get-properties]] | [[CL:​Functions:​remprop]] |                                |