所以这个函数应该用散列表中的该键的值替换x,这也是散列表的关键,但是当列表以某种方式变成< void>。为什么?这个函数变成<void>而不是交换值,为什么?
(define (var-helper L)
(for-each (lambda (x) (when (hash-has-key? *variables* x)
(swap x (hash-ref *variables* x) L)))
L))
下面是我使用的交换功能:
(define (swap x y L)
(cond ((empty? L) '())
((list? (car L))
(cons (swap x y (car L))
(swap x y (cdr L))))
((eq? x (car L))
(cons y (swap x y (cdr L))))
((cons (car L) (swap x y (cdr L))))))
swap是什么意思? – soegaard
它搜索列表(L)为x。如果x存在,它将用新值替换它,在这种情况下(hash-ref * variables * x)。 – ghostofrasputin
我将交换功能添加到我的问题以供参考^^^^ – ghostofrasputin