如何在Scheme中取消定义变量? [英] How to undefine a variable in Scheme?

查看:54
本文介绍了如何在Scheme中取消定义变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Scheme 中取消定义一个变量?这可能吗?

How to undefine a variable in Scheme? Is this possible?

推荐答案

在 Scheme 中,变量使用 lambda 或各种 let 之一定义.如果您希望其中一个是未定义的",那么您需要做的就是离开它们所在的范围.当然,这并不是真正取消定义它们,只是变量不再绑定到其先前的定义.

In Scheme, variables are defined with either lambda, or one of the various lets. If you want one of them to be 'undefined' then all you need to do is leave the scope that they're in. Of course, that's not really undefining them, it's just that the variable is no longer bound to its previous definition.

如果您使用 (define) 进行顶级定义,那么从技术上讲,您正在定义一个函数.由于 Scheme 是函数式的,函数永远不会真正消失.我想从技术上讲,它存储在某处的某种环境函数中,所以如果您非常熟悉您的实现(并且它没有以某种方式受到保护),您可能可以用您自己对 globabl 环境的定义来覆盖它.除此之外,我会说你最好的办法是重新定义函数以返回空列表——这真的和你得到的一样空.

If you're making top level definitions, using (define), then technically you're defining a function. Since Scheme is functional, functions never really go away. I suppose that technically, it's stored in some sort of environment function somewhere, so if you were intimately familiar with your implementation (and it's not safeguarded somehow) you could probably overwrite it with your own definition of the globabl environment. Barring that, I'd say that your best bet would be to redefine the function to return the null list- that's really as empty as you get.

这篇关于如何在Scheme中取消定义变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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