Hi,
I'm new to Gambit. Could anyone tell me if there's an available module system in Gambit?
Cheers, Jianshi Huang
Afficher les réponses par date
Huang Jianshi wrote:
Hi,
I'm new to Gambit. Could anyone tell me if there's an available module system in Gambit?
What do you mean exactly with the term module system? Just separately loadable/distributable code components with namespacing, or more (parametrization, functors, object systems)?
There's Snow! if you have missed it (http://snow.iro.umontreal.ca/) which does the former, and I did some module work with the same initial purpose over the last two years (see mailing list archives, "chjmodule") which I'm beginning to look into merging with Snow!. (I'm also thinking about extending it with parametrization and possibly more.)
Christian.
On Apr 20, 2007, at 2:51 AM, Christian Jaeger wrote:
What do you mean exactly with the term module system? Just separately loadable/distributable code components with namespacing, or more (parametrization, functors, object systems)?
Basically I want namespace management of symbols. I don't know what do you mean by (parametrization, functors, object systems).
There's Snow! if you have missed it (http://snow.iro.umontreal.ca/) which does the former, and I did some module work with the same initial purpose over the last two years (see mailing list archives, "chjmodule") which I'm beginning to look into merging with Snow!. (I'm also thinking about extending it with parametrization and possibly more.)
Thanks, Snow! looks exactly what I want.
Jianshi
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"))))
Hi,
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. :)
Cheers, Jianshi