Racket 中的重叠模块导入 [英] Overlapping module imports in Racket

查看:44
本文介绍了Racket 中的重叠模块导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加载图像并在 Racket 中对其进行动画处理.我可以在 Dr. Racket 中轻松完成,但我使用的是带有 Geiser 的 Emacs.要加载图像,我需要:

I want to load an image and animate it in Racket. I can do it easily in the Dr. Racket, but I am using Emacs with Geiser. To load the image I need to:

(require racket/draw)

接下来,要将此图像绘制到屏幕上,我打算使用 big-bang 模块.要加载这个模块,我必须:

Next, to draw this image onto the screen, I'm planning to use the big-bang module. To load this module I have to:

(require 2thdp/image)

但我收到此错误:

module: identifier already imported from: 2htdp/image
at: make-pen
in: racket/draw
errortrace...:

这基本上意味着我不能两次导入同一个模块.但我需要这两个库.我该如何避免这个问题?

This basically means that I can't import the same module twice. But I need both these libraries. How do I avoid this problem?

推荐答案

当两个模块提供同名函数时,可以在导入时重命名函数.

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

一种简单的方法是重命名一个模块中的所有函数,使用一些通用前缀重命名所有函数.您可以使用 prefix-in 修饰符来执行此操作 require:

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

顺便说一下,: 没有什么特别之处,它只是我见过的一个约定.代替 htdp: 前缀可以是(比如说)htdp-.无论您使用什么,它都被添加到该模块提供的每个名称之前.

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.

如果只有一个函数名称冲突,您可以使用 rename-in 重命名模块之一中的那个函数.

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

有关详细信息,请参阅require.

For more information see require.

这篇关于Racket 中的重叠模块导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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