Scheme 如何使用;cond";计划中?

Scheme 如何使用;cond";计划中?,scheme,racket,Scheme,Racket,我试图用scheme实现一个博弈论算法。我写了一段代码,名为“以牙还牙”。代码如下: (define (tit-for-two-tat my-history other-history) (cond ((empty-history? my-history) 'c) ((= 'c (most-recent-play other-history)) 'c) ((= 'c (second-most-recent-play other-history)) 'c) (else

我试图用scheme实现一个博弈论算法。我写了一段代码,名为“以牙还牙”。代码如下:

(define (tit-for-two-tat my-history other-history)
 (cond ((empty-history? my-history) 'c)
    ((= 'c (most-recent-play other-history)) 'c) 
    ((= 'c (second-most-recent-play other-history)) 'c)
    (else 'd)))
我也试着这样写:

(define (tit-for-two-tat my-history other-history)
 (cond ((empty-history? my-history) 'c)
    ((= 'c (or (most-recent-play other-history) (second-most-recent-play other-history))) 'c)
    (else 'd)))
游戏案例是“囚徒困境”。c表示坐标d表示缺陷。当我尝试运行此代码时,两种类型的代码都会出现以下错误:

expects type <number> as 1st argument, given: 'c; other arguments were: 'c
期望类型作为第一个参数,给定:'c;其他论点是:“c
我通过将此函数作为函数“play loop”的参数来运行它。游戏循环是给我的


有什么问题吗?谢谢您的帮助。

您正在调用符号
'c
上的
=
函数,但
=
需要一个数字。看起来
eq?
将是进行等价性检查的合适函数。

您正在与
'c
进行比较,后者是一个符号-然后您必须使用
eq?
进行相等性比较。或者,对于更通用的相等性测试过程,请使用
equal?
,它适用于大多数数据类型(字符串、数字、符号等),尤其是:

(define (tit-for-two-tat my-history other-history)
  (cond ((empty-history? my-history) 'c)
        ((equal? 'c (most-recent-play other-history)) 'c) 
        ((equal? 'c (second-most-recent-play other-history)) 'c)
        (else 'd)))