本文介绍了自定义eqv?/等于?计划中的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我将如何编写自己的eqv?或相等?在计划中?我会做一个cond并寻找符号,数字等,然后返回适当的#t或#f吗?

How would I go about writing my own eqv? or equal? in scheme? Would I just do a cond and look for symbol?, number?, etc and return the appropriate #t or #f?

推荐答案

按照的规定,的最低实施规范eqv?(当传递两个参数 obj1 obj2 时)为 #t 是:

As per R5RS, the minimum specifications for an implementation of eqv? (when passed two arguments obj1 and obj2) to evaluate to #tare:


  • obj1 obj2 都是 #t 或都是 #f 。 (两个布尔文字如何计算为相同的值取决于实现)。

  • obj1 obj2 都是符号,并且

  • obj1 and obj2 are both #t or both #f. (how two boolean literals evaluate to the same value is implementation dependent).
  • obj1 and obj2 are both symbols and

(string =?
(symbol-> ; string obj1)
(symbol-> string obj2))=)
=> #t


  • obj1 obj2 都是数字,在数值上等于( = ),或者都是精确的,或者都是不精确的。

  • obj1 obj2 都是字符,根据是相同字符char =?过程。

  • obj1 obj2 是空列表。

  • obj1 obj2 是对,向量或表示商店中相同位置的字符串(请参阅R5RS的3.4节)。

  • obj1 obj2 是位置标签相等的过程(在概念上用 标记了一个 lambda
    表达式在计划的实现之间这意味着不同。另请参见R5RS的4.1.4节。

  • obj1 and obj2 are both numbers, are numerically equal (=), and are either both exact or both inexact.
  • obj1 and obj2 are both characters and are the same character according to the char=? procedure.
  • both obj1 and obj2 are the empty list.
  • obj1 and obj2 are pairs, vectors, or strings that denote the same locations in the store (See section 3.4 of R5RS).
  • obj1 and obj2 are procedures whose location tags are equal (A lambdaexpression is conceptually tagged with a storage location. What that means varies between Scheme implementations. Also see section 4.1.4 of R5RS).

equal?可以用 eqv?的方式实现,因为它递归地比较了对ve的内容ctor和字符串,将 eqv?应用于其他对象,例如数字和符号。

equal? could be implemented in terms of eqv? as it recursively compares the contents of pairs, vectors, and strings, applying eqv? on other objects such as numbers and symbols.

这篇关于自定义eqv?/等于?计划中的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:32