Why we can define a function with the same name of a built-in function Racket?

十年热恋 提交于 2019-12-12 01:36:28

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/23144047/why-we-can-define-a-function-with-the-same-name-of-a-built-in-function-racket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!