Eduardo Cavazos wrote:
This is the procedure I'm using to find the current object file for a given scheme file.
(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 (first object-files)))))
Another approach to finding the "current" or "latest" object file is to pick the one with the most recent modification time.
Here's a procedure to list all the object-files for a scheme file:
(define (object-files 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 (filter object-file? (directory-files (path-directory scheme-file)))))
(let ((reattach-directory (lambda (file) (string-append (path-directory scheme-file) file))))
(map reattach-directory object-files)))))
A procedure to pick the most recent one:
(define (current-object-file scheme-file) (let ((object-files (object-files scheme-file))) (if (null? object-files) #f (first (sort-list object-files file-newer?)))))
Ed