unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Re: re-using a module
  2004-03-30 17:27 re-using a module Viktor Pavlenko
@ 2004-03-30 11:37 ` Issac Trotts
  2004-03-31  5:47 ` Thien-Thi Nguyen
  1 sibling, 0 replies; 12+ messages in thread
From: Issac Trotts @ 2004-03-30 11:37 UTC (permalink / raw)
  Cc: guile-user

On Tue, Mar 30, 2004 at 12:27:36PM -0500, Viktor Pavlenko wrote:
> > From: David Pirotte <david@altosw.be>
> > Date: 2004/03/30 Tue AM 11:13:11 EST
> > 
> > On Tue, 30 Mar 2004 10:50:45 -0500
> > prj@po.cwru.edu (Paul Jarc) wrote:
> > 
> > > Viktor Pavlenko <vvp@rogers.com> wrote:
> > > > is there a way to reload a module in guile?
> > > 
> > > Untested black magic:
> > > (use-modules (aaa))
> > > (local-remove '(app modules aaa))
> > > (use-modules (aaa))
> > 
> 
> Thanks, that's great. OTOH why isn't it done by default? Shouldn't
> guile do a cleanup if it fails to load a module? Besides I'm not too
> inclined to use "black magic" in my code...
> 
> > once a module has been used, unless you define new
> > symbols/functions/methods ... you can simply load the file
> > 
> > 	(load "xxx.scm")
> > 
> 
> This (although painful) works great too. Incidentally, I looked for
> a C equivalent, and found only scm_primitive_load. Scheme primitive-load
> differs from load in that it disregards the module's export list 
> (makes all module's symbols visible :-(

Why not use gh_eval_str("(load \"xxx.scm\"")") ?

ijt



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 12+ messages in thread

* re-using a module
@ 2004-03-30 15:34 Viktor Pavlenko
  2004-03-30 15:50 ` Paul Jarc
  0 siblings, 1 reply; 12+ messages in thread
From: Viktor Pavlenko @ 2004-03-30 15:34 UTC (permalink / raw)


Hi all,

is there a way to reload a module in guile?

Example:

file aaa.scm:
--------------------------------------------->8
(define-module (aaa) #:export (a b))

(define a 3)
(define b (lambda (x) (* x 2)) ;;missing `)'
---------------------------------------------8<

guile> (use-modules (aaa))
ERROR: In procedure list:
ERROR: end of file in ./aaa.scm
ABORT: (misc-error)
guile> (use-modules (aaa))
guile> 

The second use-modules statement does nothing.

(The behavior is exactly the same in the C interface. My program
loads user-defined modules, and if there happens to be a syntax
error in such a module I have to terminate the program. What I would
like to do is tell the user about the error, let her fix it and reload
the module).

Thanks in advance.

Viktor





_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: re-using a module
  2004-03-30 15:34 Viktor Pavlenko
@ 2004-03-30 15:50 ` Paul Jarc
  2004-03-30 16:13   ` David Pirotte
  0 siblings, 1 reply; 12+ messages in thread
From: Paul Jarc @ 2004-03-30 15:50 UTC (permalink / raw)
  Cc: guile-user

Viktor Pavlenko <vvp@rogers.com> wrote:
> is there a way to reload a module in guile?

Untested black magic:
(use-modules (aaa))
(local-remove '(app modules aaa))
(use-modules (aaa))


paul


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: re-using a module
  2004-03-30 15:50 ` Paul Jarc
@ 2004-03-30 16:13   ` David Pirotte
  0 siblings, 0 replies; 12+ messages in thread
From: David Pirotte @ 2004-03-30 16:13 UTC (permalink / raw)


On Tue, 30 Mar 2004 10:50:45 -0500
prj@po.cwru.edu (Paul Jarc) wrote:

> Viktor Pavlenko <vvp@rogers.com> wrote:
> > is there a way to reload a module in guile?
> 
> Untested black magic:
> (use-modules (aaa))
> (local-remove '(app modules aaa))
> (use-modules (aaa))

once a module has been used, unless you define new
symbols/functions/methods ... you can simply load the file

	(load "xxx.scm")


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: re-using a module
@ 2004-03-30 17:27 Viktor Pavlenko
  2004-03-30 11:37 ` Issac Trotts
  2004-03-31  5:47 ` Thien-Thi Nguyen
  0 siblings, 2 replies; 12+ messages in thread
From: Viktor Pavlenko @ 2004-03-30 17:27 UTC (permalink / raw)


> From: David Pirotte <david@altosw.be>
> Date: 2004/03/30 Tue AM 11:13:11 EST
> 
> On Tue, 30 Mar 2004 10:50:45 -0500
> prj@po.cwru.edu (Paul Jarc) wrote:
> 
> > Viktor Pavlenko <vvp@rogers.com> wrote:
> > > is there a way to reload a module in guile?
> > 
> > Untested black magic:
> > (use-modules (aaa))
> > (local-remove '(app modules aaa))
> > (use-modules (aaa))
> 

Thanks, that's great. OTOH why isn't it done by default? Shouldn't
guile do a cleanup if it fails to load a module? Besides I'm not too
inclined to use "black magic" in my code...

> once a module has been used, unless you define new
> symbols/functions/methods ... you can simply load the file
> 
> 	(load "xxx.scm")
> 

This (although painful) works great too. Incidentally, I looked for
a C equivalent, and found only scm_primitive_load. Scheme primitive-load
differs from load in that it disregards the module's export list 
(makes all module's symbols visible :-(

Thanks for your help.

Viktor





_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: re-using a module
@ 2004-03-30 18:33 Viktor Pavlenko
  0 siblings, 0 replies; 12+ messages in thread
From: Viktor Pavlenko @ 2004-03-30 18:33 UTC (permalink / raw)
  Cc: guile-user

> From: Issac Trotts <ijtrotts@ucdavis.edu>
> Date: 2004/03/30 Tue AM 06:37:32 EST
> 
> Why not use gh_eval_str("(load \"xxx.scm\"")") ?

Of course, but then what is the C API for? Also, this is a
"do-load-path-yourself" solution.

Am I complaining too much today? ;-)

Viktor





_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: re-using a module
  2004-03-30 17:27 re-using a module Viktor Pavlenko
  2004-03-30 11:37 ` Issac Trotts
@ 2004-03-31  5:47 ` Thien-Thi Nguyen
  2004-04-01  1:01   ` Viktor Pavlenko
  1 sibling, 1 reply; 12+ messages in thread
From: Thien-Thi Nguyen @ 2004-03-31  5:47 UTC (permalink / raw)
  Cc: guile-user

   From: Viktor Pavlenko <vvp@rogers.com>
   Date: Tue, 30 Mar 2004 12:27:36 -0500

   not too inclined to use "black magic" in my code...

there is a work in progress module (ice-9 gumm), snapshot at:

 http://www.glug.org/snap/core-1-4/ice-9/gumm.scm

that provides an interface to the module system internals.  you can
construct a trivial facsimile for your local guile like so:

 (define-module (ice-9 gumm))
 (define-public local-remove local-remove)
 (define-public current-module current-module)
 (define-public eval-in-module eval-in-module)
 (define-public module-ref module-ref)
 (define-public resolve-module resolve-module)
 [...]

then your code can do (use-modules (ice-9 gumm)), which may give you a
feeling of not using magic so much.  certainly it will make your code
interoperable w/ 1.4.2.  (guile-sdl and guile-pg will do this, e.g.)

in any case, i take your main point to be that load failures should not
result in inconsistent state in the first place; particular approaches
to working around this bug are of secondary concern only.  probably
1.4.1.99 will have a fix -- thanks for reminding me of this.

thi


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: re-using a module
  2004-03-31  5:47 ` Thien-Thi Nguyen
@ 2004-04-01  1:01   ` Viktor Pavlenko
  2004-04-01  5:12     ` Thien-Thi Nguyen
  2004-04-01  5:21     ` Thien-Thi Nguyen
  0 siblings, 2 replies; 12+ messages in thread
From: Viktor Pavlenko @ 2004-04-01  1:01 UTC (permalink / raw)
  Cc: guile-user

>>>>> "TTN" == Thien-Thi Nguyen <ttn@surf.glug.org> writes:

    TTN>  [...]

    TTN> there is a work in progress module (ice-9 gumm), snapshot at:

    TTN>  http://www.glug.org/snap/core-1-4/ice-9/gumm.scm

    TTN>  [...]

Thanks, I'll have a look.

    TTN> in any case, i take your main point to be that load failures
    TTN> should not result in inconsistent state in the first place;
    TTN> particular approaches to working around this bug are of
    TTN> secondary concern only.  probably 1.4.1.99 will have a fix --
    TTN> thanks for reminding me of this.

There is more to it. local-remove works only if the module haven't
been loaded. It's not possible to un-load a successfully loaded module
with it:

----------------------------------------------------------------->8
guile> (use-modules (ice-9 null))
guile> (local-remove '(app modules ice-9 null))
#f
guile> (use-modules (ice-9 null))
standard input:3:1: In expression (eval-case (# #) (else #)):
standard input:3:1: no code for module (ice-9 null)
ABORT: (misc-error)

Type "(backtrace)" to get more information or "(debug)" to enter the
debugger.
guile> 
-----------------------------------------------------------------8<

It would be cool if there was a way to reload modules too.

-- 
Viktor


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: re-using a module
  2004-04-01  1:01   ` Viktor Pavlenko
@ 2004-04-01  5:12     ` Thien-Thi Nguyen
  2004-04-03  5:17       ` Viktor Pavlenko
  2004-04-01  5:21     ` Thien-Thi Nguyen
  1 sibling, 1 reply; 12+ messages in thread
From: Thien-Thi Nguyen @ 2004-04-01  5:12 UTC (permalink / raw)
  Cc: guile-user

   From: Viktor Pavlenko <vvp@rogers.com>
   Date: Wed, 31 Mar 2004 20:01:43 -0500

   There is more to it. local-remove works only if the module haven't
   been loaded. It's not possible to un-load a successfully loaded
   module with it: [...]

probably it is better to speak of "unlinking" a module from the current
module which implies breaking a single edge, rather than "unloading"
which implies de-allocation of resources and a (potentially) cascading
process of breaking many edges.  how does this syntax strike you:

(unlink-modules MODULE-NAME [...])	; or maybe "unuse-modules" ?

perhaps this should only be available via (ice-9 session), aimed at
interactive repls primarily.

   It would be cool if there was a way to reload modules too.

eventually the module system must support complete phase separation
between reading and evaluation.  by reload, do you mean re-read, re-eval
or both?  could you give an example of how reloading would be used?

i just finished the "How to Use Modules in PLT Scheme v200" webpage; it
looks like the guile module system has a lot of enhancement opportunity
left...

thi


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: re-using a module
  2004-04-01  1:01   ` Viktor Pavlenko
  2004-04-01  5:12     ` Thien-Thi Nguyen
@ 2004-04-01  5:21     ` Thien-Thi Nguyen
  1 sibling, 0 replies; 12+ messages in thread
From: Thien-Thi Nguyen @ 2004-04-01  5:21 UTC (permalink / raw)
  Cc: guile-user

btw, work in progress docs are at:

 http://www.glug.org/docbits/guile/1.4.x/Module-System-Internals.html

thi


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: re-using a module
  2004-04-01  5:12     ` Thien-Thi Nguyen
@ 2004-04-03  5:17       ` Viktor Pavlenko
  2004-04-03  5:38         ` Viktor Pavlenko
  0 siblings, 1 reply; 12+ messages in thread
From: Viktor Pavlenko @ 2004-04-03  5:17 UTC (permalink / raw)
  Cc: guile-user

>>>>> "TTN" == Thien-Thi Nguyen <ttn@surf.glug.org> writes:

    TTN> probably it is better to speak of "unlinking" a module from
    TTN> the current module which implies breaking a single edge,
    TTN> rather than "unloading" which implies de-allocation of
    TTN> resources and a (potentially) cascading process of breaking
    TTN> many edges.  how does this syntax strike you:

    TTN> (unlink-modules MODULE-NAME [...])	; or maybe "unuse-modules" ?

    TTN> perhaps this should only be available via (ice-9 session),
    TTN> aimed at interactive repls primarily.

    TTN>    It would be cool if there was a way to reload modules too.

    TTN> eventually the module system must support complete phase
    TTN> separation between reading and evaluation.  by reload, do you
    TTN> mean re-read, re-eval or both?  could you give an example of
    TTN> how reloading would be used?

Now I realize that unloading (or unlinking) would be tricky to
implement properly; I'd happy with the guile's `load'-like
functionality to reload a module. So I think it means re-read and
re-eval.

An example where I need reloading a module is my libtour library (see
SF) where I want to be able to re-load a module for a sports
tournament without restarting the application.

-- 
Viktor


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: re-using a module
  2004-04-03  5:17       ` Viktor Pavlenko
@ 2004-04-03  5:38         ` Viktor Pavlenko
  0 siblings, 0 replies; 12+ messages in thread
From: Viktor Pavlenko @ 2004-04-03  5:38 UTC (permalink / raw)
  Cc: ttn

>>>>> "VP" == Viktor Pavlenko <vvp@rogers.com> writes:

    VP> An example where I need reloading a module is my libtour
    VP> library (see SF)

Sorry, the project home page is at http://libtour.sourceforge.net/ .

-- 
Viktor


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2004-04-03  5:38 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-30 17:27 re-using a module Viktor Pavlenko
2004-03-30 11:37 ` Issac Trotts
2004-03-31  5:47 ` Thien-Thi Nguyen
2004-04-01  1:01   ` Viktor Pavlenko
2004-04-01  5:12     ` Thien-Thi Nguyen
2004-04-03  5:17       ` Viktor Pavlenko
2004-04-03  5:38         ` Viktor Pavlenko
2004-04-01  5:21     ` Thien-Thi Nguyen
  -- strict thread matches above, loose matches on Subject: below --
2004-03-30 18:33 Viktor Pavlenko
2004-03-30 15:34 Viktor Pavlenko
2004-03-30 15:50 ` Paul Jarc
2004-03-30 16:13   ` David Pirotte

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