0
比方说,我有这样一个清单:方案特征比较
(define test '(r x -))
我想知道我怎么能区分每个值的列表中,为的exaple:
(define (distinguish test) (equal? (car test) r))
- >中当然这会返回错误,但我希望它返回#t或类似的东西。
感谢您的帮助!
比方说,我有这样一个清单:方案特征比较
(define test '(r x -))
我想知道我怎么能区分每个值的列表中,为的exaple:
(define (distinguish test) (equal? (car test) r))
- >中当然这会返回错误,但我希望它返回#t或类似的东西。
感谢您的帮助!
在代码不引用符号是可变
(define r 'x) ; define the variable r to be the symbol x
(eq? (car test) r) ; ==> #f (compares the symbol r with symbol x)
(eq? (cadr test) r) ; ==> #t (compares the symbol x with the symbol x)
(eq? (car test) 'r) ; ==> #t (compares the symbol r with the symbol r)
中的符号列表比较
(define test-list '(fi fa foo))
(define test-symbol 'fi)
(eq? (car test-list) test-symbol) ; ==> #t (compares fi with fi)
(eq? 'fi 'fi) ; ==> #t (compares fi with fi)
字在字符串比较(该问题的标题是有关字符不是符号):
(define test-string "test")
(define test-char #\t)
(eqv? (string-ref test-string 0) test-char) ; ==> #t (compares #\t with #\t)
(eqv? #\t #\t) ; ==> #t (compares #\t with #\t)
谢谢!你的回答也很有帮助。 –
你问的是如何访问符号'r','x' a nd' -',如'car','cadr'和'caddr'? – Sylwester
不,我在问怎么才能得到'正确'的操作(等于?(汽车测试)r)就好像它在比较** r **和** r **一样,因为它实际上返回'Error' –
你应该写:'(define(区分测试)(相等?(汽车测试)'r))'。 – Renzo