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] |
> I found this in the archives: > > ;;save current module > (define top (current-module)) > (define x 1) > x ; yields 1 > > ;;create and switch to a new module, called (foo bar) > (define-module (foo bar)) > (define x 2) > x ; yields 2 > > ;;switch back to the initial module > (set-current-module top) > x ; yields 1 again > > Of course it doesn't really work, because inside "foo", "top" > will be unbound. But looks like a cool way to achieve namespace > protection. This isn't good Scheme, since it potentially munches the-root-module's namespace, but with a slight variation it works, and makes the point: ;;save current module (module-define! the-root-module 'top (current-module)) (define x 1) x ; yields 1 ;;create and switch to a new module, called (foo bar) (define-module (foo bar)) (define x 2) x ; yields 2 ;;switch back to the initial module (set-current-module (module-ref the-root-module 'top)) x ; yields 1 again > The questions are: is there a way to make this work on scheme? > (Probably by making "foo" able to access toplevel symbol "top") See above attempt. > And more important, is there a way to make this work on C > (libguile)? Are there functions that do the job of > current-module, define-module and set-current-module? When forced into such ugliness, I resort to gh_eval_str (blech). > I really hesitate to use this method because Godot may render it > completely useless, but I do have to use _something_ for now :-) > and this one sounds better than the other sollution someone > offered me (apart from the fact that I lost the message with > this alternative sollution). I've learned not to wait. -russ -- "Unfortunately the only Windows feature inspired by Emacs was size." -- Nick C. in alt.religion.emacs