[gambit-list] smart-load
Eduardo Cavazos
wayo.cavazos at gmail.com
Sun Mar 22 03:37:19 EDT 2009
Hello,
Here's fun hack that's a replacement for 'load'. I use something like
this with Chicken.
If the scheme file doesn't have a corresponding object file or if the
object file is out of date, the scheme file is compiled and loaded.
Otherwise the object file is loaded.
(define (smart-load scheme-file)
(let ((object-file (current-object-file scheme-file)))
(cond ((and object-file
(file-newer? object-file scheme-file)
(not (member object-file *gambit-loaded-files*)))
(set! *gambit-loaded-files*
(cons object-file *gambit-loaded-files*))
(gambit-scheme-load object-file))
((and object-file
(file-newer? object-file scheme-file))
'already-loaded)
(else
(print "Compiling file: " scheme-file "\n")
(compile-file scheme-file)
(smart-load scheme-file)))))
Where the supporting procedures are:
(define (file-newer? a b)
(> (time->seconds (file-info-last-modification-time (file-info a)))
(time->seconds (file-info-last-modification-time (file-info b)))))
(define (current-object-file scheme-file)
(let ((object-file?
(let ((object-file-prefix
(string-append (path-strip-directory
(path-strip-extension scheme-file))
".o")))
(lambda (file)
(string-prefix? object-file-prefix file)))))
(let ((object-files
(sort-list
(filter object-file?
(directory-files (path-directory scheme-file)))
string>)))
(if (null? object-files)
#f
(string-append (path-directory scheme-file)
(first object-files))))))
Ed
More information about the Gambit-list
mailing list