This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: autoaloading facility
- To: Mikael Djurfeldt <mdj AT mdj-pc.nada.kth.se>
- Subject: Re: autoaloading facility
- From: Greg Badros <gjb AT cs.washington dot edu>
- Date: 14 Sep 1999 08:20:23 -0700
- Cc: Klaus.Schilling AT home.ivm.de, guile AT sourceware.cygnus dot com
- References: <m11QgjF-000H3iC@debian> <xy7k8pt7shj.fsf@mdj-pc.nada.kth.se>
Mikael Djurfeldt <mdj@mdj-pc.nada.kth.se> writes:
> Klaus Schilling <Klaus.Schilling@home.ivm.de> writes:
>
> > Emacs lisp has an autoloading facility which enables to load the full
> > definition of a function at the time it is needed first time. Could
> > something like that also be provided in guile? or do lexical scoping
> > and monolithic namespace prevent that?
>
> There actually exists such a facility in 1.3.2. You do:
>
> (define-module (my-module)
> :autoload (some auto loaded module) (foo bar baz))
>
> Any time when foo, bar or baz are referenced, (some auto loaded module)
> will be loaded.
Is there special support for autoloads in the root module? Autoloads
are most important for a user's .scwmrc. Also, it's more useful to have
the autoloading be specified anywhere, not just in a define-module
header. Bernard's technique seems generally useful -- it'd be nice if
its functionality were included in guile.
This gives me an idea. I asked a week or so ago if there was a better
way to conditionally use a module instead of having to repeat all of the
use-modules. The below is the simplest (and least-painful) example of
how we currently do things:
;; guile-version variable is nice to have; perhaps guile should provide it
;; (define-public guile-version (+ (string->number (major-version))
;; (/ (string->number (minor-version)) 10)))
(if (> guile-version 1.3)
(define-module (app scwm path-cache)
:use-module (ice-9 popen)
:use-module (ice-9 string-fun))
(define-module (app scwm path-cache)
:use-module (ice-9 string-fun)))
Ideally, this would be:
(define-module (app scwm path-cache)
:use-module (ice-9 string-fun)
:use-module-if (ice-9 popen) (> guile-version 1.3))
But it seems as though:
(define-module (app scwm path-cache)
:use-module (ice-9 string-fun)
:autoload (ice-9 popen) (use-ice-9-popen))
(if (> guile-version 1.3) use-ice-9-popen)
might be a way to get a similar behaviour now. (Though the
use-module-if keyword makes a lot of sense, IMO.)
Thanks,
Greg