命名空间在 Chicken Scheme 中是如何工作的?我现在正在使用 parley
egg,当我定义一个名称为 e.g. 的函数时read
,由于名称冲突而导致错误(实际上,因为我的 read
覆盖了 parley
自己的 read
,并且它被错误的类型调用。
代码如下:
(use parley)
(define (read p) p) ; This `read` function conflicts.
(let loop ((l (parley "> ")))
(if (or (eof-object? l)
(equal? l "quit"))
(print "bye!")
(begin
(printf "you typed: ~s~%" l)
(loop (parley "> ")))))
如何避免此类碰撞?
更新
我减少了重现此代码所需的代码:
(use parley)
(define (read p) p)
这得到以下错误:
Error: illegal non-atomic object: #<input port "readline.scm">
显然,我的 read
函数与 parley
冲突read
.但是我不知道如何在不重命名我的函数的情况下避免这种情况。
最佳答案
根据 the documentation您可以使用与在模块中导入模块时相同的技巧。然后你有很多选择,比如前缀:
(use (prefix parley parley:)) ; all imported symbols have been prefixed with "parley:"
关于Chicken Scheme 中的命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28858017/