[gambit-list] Bug

Marc Feeley feeley at iro.umontreal.ca
Fri May 11 07:34:55 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11-May-07, at 7:04 AM, Christian Jaeger wrote:

> Marc Feeley wrote:
>> Never redefine or mutate a variable whose name starts with "##"
>
> Just a note to Brad: I'm prefixing my own unsafe functions with @  
> (I've
> never (mis)used ## for this purpose since I've always been using
> namespaces for module separation purposes (through chjmodule)).

Another way to avoid name clashes is to use Gambit's "namespace"  
declaration.  You normally would split the code of a module into 2  
files, the interface file and the implementation file.  By convention  
the name of the interface file is the name of the implementation file  
followed by "#" before the extension.  So if you are implementing a  
module "brad" which exports the functions "foo" and "vector-copy" you  
would write:

interface file:
- -------------------------------------------------------
;;; File: "brad#.scm"
(namespace ("brad#" foo vector-copy)) ;; "exports"
- -------------------------------------------------------

implementation file:
- -------------------------------------------------------
;;; File: "brad.scm"
(namespace ("brad#"))
(##include "~~/lib/gambit#.scm")
(include "brad#.scm")

(define (foo x) 999)
(define (vector-copy y) (list->vector (baz (vector->list y))))
(define (baz z) (reverse z)) ;; baz is a private function
- -------------------------------------------------------

To use this module from the file "client.scm" you need to do:

- -------------------------------------------------------
;;; File: "client.scm"
(include "brad#.scm")

(pp (vector-copy '#(1 2 3))) ;; calls brad#vector-copy
- -------------------------------------------------------

So "include"ing an interface file has the effect of "importing" a  
module's exports.

Marc

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)

iD8DBQFGRFTf//V9Zc2T/v4RAknwAJ9u/oMX8cNv6OHh+Qjx2zW1DAnd6ACeIv4j
gKGXVY0y8yTR02LEqZIUfeQ=
=HXVE
-----END PGP SIGNATURE-----



More information about the Gambit-list mailing list