文档章节

Equality Predicates

TinkerS
 TinkerS
发布于 2013/05/23 09:44
字数 569
阅读 19
收藏 0

Here we describe functions that test for equality between 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, and nil otherwise. 

If object1 and object2 are integers with the same value, they are considered to be the same object (i.e., eq returns t). If object1 and object2 are symbols with the same name, they are normally the same object—but see Creating Symbols for exceptions. 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. See Creating Symbols. 
          (eq (make-symbol "foo") 'foo)
               ⇒ nil
 — Function: equal object1 object2

This function returns t if object1 and object2 have equal components, and 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. See Text Properties. 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). (see 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

本文转载自:http://www.gnu.org/software/emacs/manual/html_node/elisp/Equality-Predicates.html

共有 人打赏支持
TinkerS
粉丝 8
博文 55
码字总数 12670
作品 0
高级程序员
私信 提问
《k8s-1.13版本源码分析》- 调度器设计

本文原始地址:https://farmer-hutao.github.io/k8s-source-code-analysis/core/scheduler/desigh.html github项目地址:https://github.com/farmer-hutao/k8s-source-code-analysis 1. 概述......

CloudGeek
02/21
0
0
Oracle提高SQL执行效率的三种方法

Oracle提高SQL执行效率的三种方法 (修改了一下) 要提高SQL在Oracle里的执行效率,优化应用的业务逻辑是最主要的,从技术层面来讲Oracle也提供了一些方法,今天主要讲3种: Oracle提供了多种方...

突突突酱
01/18
0
0
聊聊spring cloud gateway的RouteLocator

序 本文主要研究一下spring cloud gateway的RouteLocator RouteLocator spring-cloud-gateway-core-2.0.0.RC2-sources.jar!/org/springframework/cloud/gateway/route/RouteLocator.java 其有......

go4it
2018/06/06
0
0
深入分析Kubernetes Critical Pod(四)

摘要:本文分析了DeamonSetController及PriorityClass Validate时,对CriticalPod的所做的特殊处理。 Daemonset Controller对CriticalPod的特殊处理 深入分析Kubernetes Critical Pod系列:深...

WaltonWang
2018/07/12
0
0
Neo4j 2.3.2 发布,面向网络的数据库

Neo4j 2.3.2 发布,更新如下: Import Tool: import-tool can now configure custom characters for quoting and field delimiting, using --quote and --delimiter respectively. #6034 Ker......

淡漠悠然
2016/01/27
2.1K
8

没有更多内容

加载失败,请刷新页面

加载更多

activiti6+springboot连接mysql

application.properties spring.datasource.url=jdbc:mysql://130.51.23.249:3306/activiti6ui?characterEncoding=utf8&useSSL=truespring.datasource.username=saspring.datasource.passw......

Danni3
22分钟前
1
0
PHP教程中验证正整数is_int($value+0),为什么要这样?

最近学习PHP应用,其中有一段是要验证变量是否为正整数,除了is_numeric($value)外,还要加上is_int($value+0)且($value+0) > 0,为什么还要 +0呢?直接验证$value不行吗? ,只要 is_int($...

dragon_tech
34分钟前
1
0
毕业季,我的Linux求职之路

秋招终于告一段落了,本硕的七年求学之路也快画上了句号。回首求职的这一段日子,痛苦并快乐着。感谢所有陪伴着我走过这一段路程的同学,所有的辛酸都值得铭记。求职的过程中在网上看了很多的...

xiangyunyan
41分钟前
1
0
springMvc异常处理定制化

1、扩展SimpleMappingExceptionResolver来实现springMvc的定制 import org.apache.commons.codec.binary.Base64;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.......

重城重楼
今天
4
0
OSChina 周四乱弹 —— Im fine

Osc乱弹歌单(2019)请戳(这里) 【今日歌曲】 @LuckyXu:分享戴荃的单曲《小荃拳之歌》: 手机党少年们想听歌,请使劲儿戳(这里) 今天遇到倒霉事了, @ FalconChen :电梯宕机了我靠 但是...

小小编辑
今天
971
19

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部