[gambit-list] Available module system?

Christian Jaeger christian at pflanze.mine.nu
Thu Apr 19 15:29:26 EDT 2007


Huang Jianshi wrote:
> Basically I want namespace management of symbols. I don't know what  
> do you mean by (parametrization, functors, object systems).

Parametrization means that you can specify the imports which some module
is doing. If you have e.g. a module A which requires the services of
some other module X, you can tell while importing A into your work what
X should be imported into A. This way you can change the workings of A
in more liberal ways than what the author of A is offering with the
functions he is exporting. (You could for example substitute the
function |car|, normally from R5RS, with something else for the global
scope in A.)

Functors (in the ML sense) are, I believe, defined as functions which
map a set of functions to a set of other functions. At the end of this
mail I've appended an example of a functor named A which passes two
functions (for mappig and filtering) on to a receiver "recv", and an
example of it's usage on (vector based) strings instead of lists (not a
particularly good example since decomposing vectors on each item isn't
an efficient approach, I hope you still get the idea). You may notice
that this is basically what I've described as "parametrization" above;
module parametrization goes one step further in that you don't pass
single functions in and out, but groups of them, known as "modules". So
if A is a module instead of a function you'd just say something like
(import (A list-functions: my-string-as-list-access-module)) and get the
exported map and filter with 'modifications'. Unlike the functor, a
module  system with parametrization would also include macros in the
parametrization process; this allows for example to derive both lazy and
strict functions from the same sources (e.g. srfi-1 and srfi-40 could
both share a common list manipulation library with lazyness annotations).

Object systems are imho interesting in the context of module systems
because they usually don't adhere lexical scoping (but system-global
scope). But I think it could be interesting to introduce lexical
scoping, too. ("So code in one place doesn't suffer from imports in
another place.") But I haven't examined this enough yet (am I mislead?).

Christian.


;; Functor example:

(define (A car cdr cons null?
	   recv)
  (recv
   (lambda (fn lis)
     (let _map ((lis lis))
       (if (null? lis)
	   lis
	   (cons (fn (car lis))
		 (_map (cdr lis))))))
   (lambda (fn lis)
     (let _filter ((lis lis))
       (if (null? lis)
	   lis
	   (let ((v (car lis)))
	     (if (fn v)
		 (cons v
		       (_filter (cdr lis)))
		 (_filter (cdr lis)))))))))

(A (lambda (s)
     (string-ref s 0))
   (lambda (s)
     (substring s 1 (string-length s)))
   (lambda (ch s)
     (let* ((len (string-length s))
	    (s2 (make-string (+ 1 len))))
       (string-set! s2 0 ch)
       (let lp ((i 1))
	 (if (> i len)
	     s2
	     (begin
	       (string-set! s2 i
			    (string-ref s (- i 1)))
	       (lp (+ i 1)))))))
   (lambda (s)
     (= (string-length s) 0))
   ;; use the new functions:
   (lambda (map filter)
     (println (map (lambda (ch)
		     (case ch
		       ((#\e) #\E)
		       (else ch)))
		   "Hello World"))
     (println (filter (lambda (ch)
			(not (char=? ch #\e)))
		      "Hello World"))))



More information about the Gambit-list mailing list