eslip中eq与equal的区别

File: elisp,  Node: Equality Predicates,  Prev: Type Predicates,  Up: Lisp Data Types

 

2.7 Equality Predicates

=======================

 

Here we describe functions that test for equality between any two

objects.  Other functions test equality of contents between objects of

specific types, e.g., strings.  For these predicates, see the

appropriate chapter describing the data type.

 

 -- Function: eq object1 object2

     This function returns `t' if OBJECT1 and OBJECT2 are the same

     object, `nil' otherwise.

 

     `eq' returns `t' if OBJECT1 and OBJECT2 are integers with the same

     value.  Also, since symbol names are normally unique, if the

     arguments are symbols with the same name, they are `eq'.  For

     other types (e.g., lists, vectors, strings), two arguments with

     the same contents or elements are not necessarily `eq' to each

     other: they are `eq' only if they are the same object, meaning

     that a change in the contents of one will be reflected by the same

     change in the contents of the other.

 

          (eq 'foo 'foo)

               => t

 

          (eq 456 456)

               => t

 

          (eq "asdf" "asdf")

               => nil

 

          (eq "" "")

               => t

          ;; This exception occurs because Emacs Lisp

          ;; makes just one multibyte empty string, to save space.

 

          (eq '(1 (2 (3))) '(1 (2 (3))))

               => nil

 

          (setq foo '(1 (2 (3))))

               => (1 (2 (3)))

          (eq foo foo)

               => t

          (eq foo '(1 (2 (3))))

               => nil

 

          (eq [(1 2) 3] [(1 2) 3])

               => nil

 

          (eq (point-marker) (point-marker))

               => nil

 

     The `make-symbol' function returns an uninterned symbol, distinct

     from the symbol that is used if you write the name in a Lisp

     expression.  Distinct symbols with the same name are not `eq'.

     *Note Creating Symbols::.

 

          (eq (make-symbol "foo") 'foo)

               => nil

 

 -- Function: equal object1 object2

     This function returns `t' if OBJECT1 and OBJECT2 have equal

     components, `nil' otherwise.  Whereas `eq' tests if its arguments

     are the same object, `equal' looks inside nonidentical arguments

     to see if their elements or contents are the same.  So, if two

     objects are `eq', they are `equal', but the converse is not always

     true.

 

          (equal 'foo 'foo)

               => t

 

          (equal 456 456)

               => t

 

          (equal "asdf" "asdf")

               => t

          (eq "asdf" "asdf")

               => nil

 

          (equal '(1 (2 (3))) '(1 (2 (3))))

               => t

          (eq '(1 (2 (3))) '(1 (2 (3))))

               => nil

 

          (equal [(1 2) 3] [(1 2) 3])

               => t

          (eq [(1 2) 3] [(1 2) 3])

               => nil

 

          (equal (point-marker) (point-marker))

               => t

 

          (eq (point-marker) (point-marker))

               => nil

 

     Comparison of strings is case-sensitive, but does not take account

     of text properties--it compares only the characters in the

     strings.  Use `equal-including-properties' to also compare text

     properties.  For technical reasons, a unibyte string and a

     multibyte string are `equal' if and only if they contain the same

     sequence of character codes and all these codes are either in the

     range 0 through 127 (ASCII) or 160 through 255

     (`eight-bit-graphic').  (*note Text Representations::).

 

          (equal "asdf" "ASDF")

               => nil

 

     However, two distinct buffers are never considered `equal', even if

     their textual contents are the same.

 

   The test for equality is implemented recursively; for example, given

two cons cells X and Y, `(equal X Y)' returns `t' if and only if both

the expressions below return `t':

 

     (equal (car X) (car Y))

     (equal (cdr X) (cdr Y))

 

   Because of this recursive method, circular lists may therefore cause

infinite recursion (leading to an error).

 

 -- Function: equal-including-properties object1 object2

     This function behaves like `equal' in all cases but also requires

     that for two strings to be equal, they have the same text

     properties.

 

          (equal "asdf" (propertize "asdf" '(asdf t)))

               => t

          (equal-including-properties "asdf"

                                      (propertize "asdf" '(asdf t)))

               => nil

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值