Namespaces in Chicken Scheme

寵の児 提交于 2020-01-04 02:42:09

问题


How do namespaces work in Chicken Scheme? I am now using the parley egg, and when I define a function with the name e.g. read, that causes an error because of name clashing (actually, because my read overwrites parley's own read, and it is invoked with wrong type.

Here's the code:

(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 "> ")))))

How can I avoid collisions like these?

UPDATE

I've reduced the code necessary to reproduce this:

(use parley)
(define (read p) p)

this gets the following error: Error: illegal non-atomic object: #<input port "readline.scm">

Obviously, my read function is clashing with parley read. But I don't know how to avoid this without renaming my function.


回答1:


According to the documentation you can use the same tricks as when you import modules in modules. You then have lots of options, like prefix:

(use (prefix parley parley:)) ; all imported symbols have been prefixed with "parley:"



回答2:


It was not that obvious. It turns out that read is an essential function in Scheme that converts external representations of Scheme objects into the objects themselves. Overwriting it is not a good idea, because users of my library or app probably assume that read is not overwritten, and try to use it as a parser.

But Chicken Scheme should be giving a warning, not an error, so that's probably a bug in Chicken.It is to be determined if it is actually csi the one who is at fault, instead of Parley.

In any case, it's a terrible idea to overwrite read.



来源:https://stackoverflow.com/questions/28858017/namespaces-in-chicken-scheme

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