[gambit-list] Valid namespace prefix
Marc Feeley
feeley at iro.umontreal.ca
Mon Jul 30 12:50:46 EDT 2007
On 30-Jul-07, at 10:32 AM, James Long wrote:
> Here's the main the problem I'm trying to solve: I'm trying to figure
> out how to export records or types (or anything that uses macro
> rewriting). my system will use records extensively, using
> define-structure or define-type. Obviously I don't want to have to
> manually export every function that define-type creates.
>
> I suppose there's an argument to be made that the module owning a
> record type should be the only thing with complete access to it, and
> it should delegate control by exporting getter/setter functions and
> constructors. However, it seems like that could get tedious.
Just define your own define-type like macro that does what you want:
(my-define-type bar a b c)
should expand to
(##namespace ("bar#" make-bar bar? bar-a bar-a-set! bar-b bar-b-set!))
(define-type bar a b c)
If you want to experiment with different namespace separators in gsi,
just compile this file:
;; File: "gambcext.scm"
(declare (block))
(define ##namespace-separators '(#\# #\:))
(set! ##namespace-separators ##namespace-separators)
(define (##full-name? sym) ;; full name if it contains a namespace
separator
(let ((str (##symbol->string sym)))
(let loop ((i (##fixnum.- (##string-length str) 1)))
(if (##fixnum.< i 0)
#f
(if (##memq (##string-ref str i) ##namespace-separators)
#t
(loop (##fixnum.- i 1)))))))
(define (##valid-prefix? str)
;; non-null name followed by a namespace separator at end is
;; valid as is the special prefix ""
(let ((l (##string-length str)))
(or (##fixnum.= l 0)
(and (##not (##fixnum.< l 2))
(##memq (##string-ref str (##fixnum.- l 1))
##namespace-separators)))))
and put it in the Gambit installation directory so that it is
automatically loaded. You can change the namespace-separators at run
time with a
(set! ##namespace-separators '(#\# #\: ...))
Marc
More information about the Gambit-list
mailing list