Sergi Mansilla
Sergi Mansilla

Reputation: 12803

Namespaces in Chicken Scheme

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.

Upvotes: 3

Views: 678

Answers (2)

Sylwester
Sylwester

Reputation: 48765

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:"

Upvotes: 5

Sergi Mansilla
Sergi Mansilla

Reputation: 12803

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.

Upvotes: 1

Related Questions