* dynamic module creation
@ 2009-02-01 7:58 Julian Graham
2009-02-01 12:04 ` Andy Wingo
0 siblings, 1 reply; 5+ messages in thread
From: Julian Graham @ 2009-02-01 7:58 UTC (permalink / raw)
To: guile-user
Hi Guilers,
Is there a way to create a module at runtime and evaluate expressions
in it using a dynamically-created set of module imports? I want to do
something along the lines of:
(save-module-excursion
(lambda ()
(define-module (my-dynamic-module-name)
#:use-module (a-module-i-decided-to-include-at-runtime)
#:pure)
(do-something)))
...except `define-module' doesn't like being called from anywhere
except the top level. I also tried `resolve-module', the
documentation for which says:
Find the module named NAME and return it. When it has not already
been defined, try to auto-load it. When it can't be found that way
either, create an empty module.
This works as advertised -- it really does create an empty module, but
it's completely empty: No core Scheme syntax, not even any syntactic
sugar like '@ to help you get at stuff from the core. It's an utterly
blank environment. Is there some way to get the module-creation
behavior of `resolve-module' but also be able to include stuff from
other modules in the resulting environment?
Regards,
Julian
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dynamic module creation
2009-02-01 7:58 dynamic module creation Julian Graham
@ 2009-02-01 12:04 ` Andy Wingo
2009-02-01 19:29 ` Neil Jerram
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Andy Wingo @ 2009-02-01 12:04 UTC (permalink / raw)
To: Julian Graham; +Cc: guile-user
On Sun 01 Feb 2009 08:58, Julian Graham <joolean@gmail.com> writes:
> Is there some way to get the module-creation
> behavior of `resolve-module' but also be able to include stuff from
> other modules in the resulting environment?
guile> (resolve-module '(foo))
$1 = #<directory (foo) b7f11bb0>
guile> (beautify-user-module! $1)
$2 = (#<interface (guile) b7f8aef0>)
guile> (module-ref $1 'sin)
$3 = #<procedure sin (z)>
guile>
Cheers,
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dynamic module creation
2009-02-01 12:04 ` Andy Wingo
@ 2009-02-01 19:29 ` Neil Jerram
2009-02-02 9:49 ` Ludovic Courtès
[not found] ` <2bc5f8210902011259w54b5e427x1de20fb88143d441@mail.gmail.com>
2 siblings, 0 replies; 5+ messages in thread
From: Neil Jerram @ 2009-02-01 19:29 UTC (permalink / raw)
To: Julian Graham; +Cc: Andy Wingo, guile-user
Andy Wingo <wingo@pobox.com> writes:
> On Sun 01 Feb 2009 08:58, Julian Graham <joolean@gmail.com> writes:
>
>> Is there some way to get the module-creation
>> behavior of `resolve-module' but also be able to include stuff from
>> other modules in the resulting environment?
>
> guile> (resolve-module '(foo))
> $1 = #<directory (foo) b7f11bb0>
> guile> (beautify-user-module! $1)
> $2 = (#<interface (guile) b7f8aef0>)
> guile> (module-ref $1 'sin)
> $3 = #<procedure sin (z)>
> guile>
And for an example of this, see `use-elisp-file' in
lang/elisp/interface.scm.
Neil
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: dynamic module creation
2009-02-01 12:04 ` Andy Wingo
2009-02-01 19:29 ` Neil Jerram
@ 2009-02-02 9:49 ` Ludovic Courtès
[not found] ` <2bc5f8210902011259w54b5e427x1de20fb88143d441@mail.gmail.com>
2 siblings, 0 replies; 5+ messages in thread
From: Ludovic Courtès @ 2009-02-02 9:49 UTC (permalink / raw)
To: guile-user
Hi,
Andy Wingo <wingo@pobox.com> writes:
> On Sun 01 Feb 2009 08:58, Julian Graham <joolean@gmail.com> writes:
>
>> Is there some way to get the module-creation
>> behavior of `resolve-module' but also be able to include stuff from
>> other modules in the resulting environment?
>
> guile> (resolve-module '(foo))
> $1 = #<directory (foo) b7f11bb0>
You could also use:
(let ((m (make-module)))
(set-module-name! m '(foo))
m)
but you still need this ugly part:
> guile> (beautify-user-module! $1)
> $2 = (#<interface (guile) b7f8aef0>)
Thanks,
Ludo'.
^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <2bc5f8210902011259w54b5e427x1de20fb88143d441@mail.gmail.com>]
* Re: dynamic module creation
[not found] ` <2bc5f8210902011259w54b5e427x1de20fb88143d441@mail.gmail.com>
@ 2009-02-04 0:30 ` Neil Jerram
0 siblings, 0 replies; 5+ messages in thread
From: Neil Jerram @ 2009-02-04 0:30 UTC (permalink / raw)
To: Julian Graham; +Cc: Andy Wingo, guile-user
Julian Graham <joolean@gmail.com> writes:
> Incidentally, my naive attempt to refine the behavior of
> `beautify-user-module!' straight-up failed:
>
> guile> (define m (resolve-module '(foo)))
> guile> (let ((interface (make-module 31)))
> ... (set-module-name! interface (module-name m))
> ... (set-module-kind! interface 'interface)
> ... (set-module-public-interface! m interface))
> #f
> guile> (set-module-uses! m '((guile) :select (if)))
> ((guile) :select (if))
> guile> (set-current-module m)
> #<directory (guile-user) b7d61630>
> guile> if
> Segmentation fault
I haven't managed to test this yet, but I think your
`(set-module-uses! m '((guile) :select (if)))' should be
`(set-module-uses! m (list (resolve-interface '(guile) #:select '(if))))'.
(And we should also add type-checking to set-module-uses!)
Regards,
Neil
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-02-04 0:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-01 7:58 dynamic module creation Julian Graham
2009-02-01 12:04 ` Andy Wingo
2009-02-01 19:29 ` Neil Jerram
2009-02-02 9:49 ` Ludovic Courtès
[not found] ` <2bc5f8210902011259w54b5e427x1de20fb88143d441@mail.gmail.com>
2009-02-04 0:30 ` Neil Jerram
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).