Hello,
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)))))
Comments welcome.
Ed
Afficher les réponses par date
(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)))))
Comments welcome.
I don't have the utility functions that you use in that function, but if I read it correctly, it contains the same error that I made when implementing a function that does that very thing: it compares strings lexicographically, so if you have ten .o* files, it will choose .o2 and not .o10.
/Per
Per Eckerdal wrote:
(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)))))
I don't have the utility functions that you use in that function
Ah yes... I'm using SRFI-1 and SRFI-13. I'm using the ones from snow, but I'm not actually using snow. I just extracted the files I needed. But anyway, many thanks to Jeremie for packaging these for Gambit!
it compares strings lexicographically so if you have ten .o* files, it will choose .o2 and not .o10.
Yup.
There is also another area where this procedure doesn't model exactly what Gambit does. Gambit will load the highest number in a *contiguous* range starting from 1. I.e. if there are versions 1, 2, 3, 4, 5, it'll load 5. But if you have a "hole" in the numbers, e.g. if you remove version 3, Gambit'll load 2 as the latest version and create 3 if you compile again. However at this point, if you havent deleted versions 4 and 5, it'll load 5, not 3! :-) So don't make holes in the version list. :-)
Ed
There is also another area where this procedure doesn't model exactly what Gambit does. Gambit will load the highest number in a *contiguous* range starting from 1. I.e. if there are versions 1, 2, 3, 4, 5, it'll load 5. But if you have a "hole" in the numbers, e.g. if you remove version 3, Gambit'll load 2 as the latest version and create 3 if you compile again. However at this point, if you havent deleted versions 4 and 5, it'll load 5, not 3! :-) So don't make holes in the version list. :-)
Oh, I didn't know that. Interesting.
(About the double load issue and that I said it's an OS limitation: I'm not 100% sure about that. I think there has been some discussion about that on list earlier. But the exception is an os-exception, which is a pain because there is no easy way that I know of to tell the difference between double load and other problems.)
/Per
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