This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

First primitive demonstration of a module system for guile



Hi,

I've made guile-1.3 sources available which include a primitive c
based module system (see modules.c and symbols.c).  I've removed the
old scheme based module system completely and stripped down boot-9 to
a minimum.

The module system is not complete but the basic machinery is there:

scm_apply_in_module (proc, arg1, args, module)
scm_eval_in_module (x, env, module)
scm_get_current_module ()
scm_clear_module(v)
scm_export_symbols(l)
scm_friend_symbols(l)
scm_module_ref(mod, sym)
create_new_module()
find_create_package (s)
scm_module_define(s)
scm_package_show(s)
scm_module_open_all(l)


Using these functions it is (should be :>) quite easy to implement the
API "first class environments" described by Jim Blandy in his mail
"First-class environment proposal".  With one exception:
symbols from other modules are *not* copied into the current obarray
(environment) but are cached in scm_foreign_obarray.  That means that
the "eval environment" concept is *not* supported -- I don't know if
that's a good concept anyway. :)  Instead it is possible to shadow top level
bindings from other modules (as in scheme48).


Installation:

1. Get the sources from ftp.tfh-berlin.de/pub/incoming/guile13-module-hack.tar.gz
2. tar xzf guile13-module-hack.tar.gz
3. cd guile-core-dev; ./configure --disable-shared --disable-dynamic-linking --prefix=/var/tmp; make install
4. Ignore all warnings :)
5. Test it: 


gdb /var/tmp/bin/guile

(module-define 'search/regex)
(export '(version))
(friend '(protected-closure))
(define version 3.14)
(define private 0)
(define (protected-closure x) (set! private (+ private x)) private)

(module-define 'search/regexp)
(export '(mumpitz1 mumpitz2))
(define mumpitz1 ((module-ref 'search/regex 'protected-closure) 1))
(define mumpitz2 ((module-ref 'search/regex 'protected-closure) 1))

(module-define 'misc/my-test)
(module-open '(search/regex search/regexp))
version -> 3.14
mumpitz1 -> 1
mumpitz2 -> 2
private -> error
protected-closure -> error
(module-ref 'search/regex 'protected-closure)
          -> ERROR: the symbol is not accessible to you.                   

; bind symbol search/regexp in the current module to 12
(define search/regexp 12)

; look up symbol 'search/regexp in module_hash -> module
; then look up symbol 'mumpitz in that module's obarray
(module-ref 'search/regexp 'mumpitz1) -> 1

; look up search/regexp in current hash
search/regexp -> 12


6. Improve the code... :)



Regards,
Jost