Overlapping module imports in Racket

自古美人都是妖i 提交于 2019-12-01 17:34:46
Greg Hendershott

When two modules provide functions with the same name, you can rename the functions on import.

A simple way to do this is to rename all the functions from one of the modules, renaming all of them using some common prefix. You can do this with the prefix-in modifier to require:

(require racket/draw)
(require (prefix-in htdp: 2htdp/image))

make-pen      ; the `make-pen` from racket/draw
htdp:make-pen ; the `make-pen` from 2htdp

By the way, there is nothing special about the :, it's just a convention I've seen used. Instead of htdp: the prefix could be (say) htdp-. Whatever you use, it is prepended to every name provided by that module.

If just one function name conflicts, you could rename just that one function from one of the modules, using rename-in.

For more information see require.

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