[gambit-list] blackhole question

Per Eckerdal per.eckerdal at gmail.com
Sun Aug 1 17:41:09 EDT 2010

28 jul 2010 kl. 10.52 skrev Milos Negovanovic:

> I am new to scheme, gambit and blackhole! Have a look at the fallowing
> example:
> milosn at box gambit $ cat a.scm
> (define (test)
>  (println "A!"))
> milosn at box gambit $ cat b.scm 
> (define (test)
>  (println "B!"))
> milosn at box gambit $ cat mod.scm 
> (import a
>        b)
> (test)
> milosn at box gambit $ bsc -i mod.scm
> Loaded Black Hole.
> A!
> My question is: why is it printing "A!" when test procedure was redefined in
> b.scm and b.scm is imported after a.scm?

Hi Milos,

What you are describing is one of the very core reasons to why Black Hole is needed. Black Hole makes sure that the two different procedures with the same name do not interfere with each other. Take this example:

(define (test) "A!")

(define (test) "B!")

(import a)
(define (c) (test))

(import b)
(define (d) (test))

(import c d)
(println (c) (d))

I didn't test it, but it ought to print "A!B!". This is very important in Black Hole, as it enables people to write code without having to worry about whether the name is already used by someone else.

It might help to know that this is done internally by naming the two procedures a#test and b#test, respectively (unless there are already modules with that name, in which case a unique name before the hash mark is chosen automatically.)

In your example, Black Hole probably ought to give a warning message that the name test is imported twice. Instead, it arbitrarily chooses to import test from a.scm

Another thing that might help to know is that you can choose to import only some of the things that a module exports like these examples:

(import (except: (std srfi/1) reverse!))
(import (only: (std srfi/1) reverse!))

You can also add a prefix to the names like this:

(import (prefix: (std srfi/1) 1-))

There's also a function to rename exports but I guess that's off topic.


More information about the Gambit-list mailing list