[gambit-list] Available module system?

Huang Jianshi jianshi.huang at gmail.com
Mon Apr 23 15:28:40 EDT 2007


On Apr 20, 2007, at 4:29 AM, Christian Jaeger wrote:

> 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.)

Yes, that's also what I want. I also want some mechanism that can  
help me manage the symbols' namespace. Something like:

(module A
	(depends-on: X Y Z ...)         ; when loading A, X Y Z will be  
loaded first and their dependencies will also be loaded recursively.
	(imports-from: (X x-sym1 x-sym2 ...))
	(imports-all-from: Y)
	(imports-all-but: (Z sym-not-needed ...))
	(exports: sym1 sym2 ...)
	(exports-from: X x-sym1 x-sym2 ...)
	(exports-all-from: Y)
	(exports-all-but: (Z symbol-not-exported ...))

I came from a CL background so maybe my view is limited.

> 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).

Ah, this give me some enlightenment on module parametrization.

> 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?).

I don't get it quite much. But I can see that lexical scoping is  
quite important.

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

Cool. I got the idea. Thank you very much. :)


More information about the Gambit-list mailing list