This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: autoaloading facility
>>>>> "Greg" == Greg Badros <gjb@cs.washington.edu> writes:
Greg> 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?
Greg> I second this query/request-- Scwm would benefit from
Greg> autoloading, for sure.
It is easy to implement such an autoloading facility for modules.
First consider the following module:
(define-module (auto auto))
(define-public *auto* '())
(define-public (autoload module . symbols)
(for-each
(lambda (sym)
(let ((res (assq sym *auto*)))
(if res
(if (equal? (cdr res) module)
'deja-fait
'pas-2-modules-actuellement)
(set! *auto* (cons (cons sym module) *auto*)))))
symbols))
(define autoload-binder
(lambda (m s define?)
(if define?
(let ((b (make-undefined-variable s)))
(module-obarray-set! (module-obarray m) s b)
b)
(begin
(let ((res (assq s *auto*)))
(if res
(begin (display ";;; autoload module ")
(display (cdr res)) (newline)
(process-use-modules (list (cdr res)))
(module-obarray-ref
(module-obarray (resolve-interface (cdr res))) s))
#f))))))
(set-module-binder! (module-public-interface (current-module)) autoload-binder)
Then put the following code in your application:
(use-modules (auto auto))
(autoload '(stklos-3.0b2 Button)
'<Label> '<Button> '<Check-button> '<Radio-button>)
As soon as any of the symbol '<Label> '<Button> '<Check-button> or
'<Radio-button> is read, module (stklos-3.0b2 Button) is loaded.
This code is part of guile-stklos-1.3.3 (in contrib/misc at red-bean).
Originally, this kind of autoloading was available in STklos.
--
B. Urban