使用集合!更改 drscheme 中变量的值 [英] using set! to change the value of a variable in drscheme

查看:30
本文介绍了使用集合!更改 drscheme 中变量的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除二叉搜索树中出现的某个值.这是我目前所拥有的:

I'm trying to delete an occurrence of some value in a binary search tree. This is what I have so far:

(define removeBin (lambda (x t)
       (cond ((< x (car t)) (removeBin x (cadr t)))
             ((> x (car t)) (removeBin x (caddr t)))
             ((equal? x (car t)) 
                   (if(and (null? (cadr t)) (null? (caddr t))) '()
                (let ((r (replacement t))) ((set! (car t) r) (removeBin r t)))))))) 

它给了我以下错误:set!: not an identifier in: (car t)这意味着什么?我该如何修复它以便设置!会起作用吗?

It's giving me the following error: set!: not an identifier in: (car t) What does that mean? and how can I fix it so that set! would work?

谢谢

推荐答案

如错误消息所述,(car t) 不是有效标识符,因此其值无法更改.

As the error message explains, (car t) is not a valid identifier, and thus its value cannot be changed.

>

你需要像这样使用set-car!:

(set-car! t r)

这将 tcar 更改为 r.

This changes the car of t to r.

这篇关于使用集合!更改 drscheme 中变量的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆