Why we can define a function with the same name of

2019-09-06 13:44发布

问题:

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.