为什么我们可以用一个内置的函数球拍定义一个同名的函数? [英] Why we can define a function with the same name of a built-in function Racket?
问题描述
(define(car xy)(+ xy))
并使用 car
作为加法函数。同时,我们失去了内置函数 car
。为什么球拍允许这样做?我们如何恢复丢失的内置函数,这里是 car
。
定义仅影响当前模块(并且,如果您导出定义,则导入您的模块的任何其他模块)。如果你想在你的模块中使用 car
作为别的东西,你总是可以用不同的名字导入Racket的内置函数。例如:
(要求(仅限于 - 在球拍/底座(车拍)))
code>
现在,您可以使用 racket-car
在 car
函数中。
We can define a new function like this:
(define (car x y) (+ x y))
And use car
as an add function. Meanwhile, we lost the built-in function car
. Why does Racket allow this? How could we recover the lost built-in function, here is car
.
Definitions affect the current module only (and, if you export your definition, then any other modules that import your module). You can always import Racket's built-in functions under a different name, if you want to use car
in your module for something else. For example:
(require (only-in racket/base (car racket-car)))
Now, you can use racket-car
to refer to the built-in car
function.
这篇关于为什么我们可以用一个内置的函数球拍定义一个同名的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!