Hi Ludovic, On Tue 20 Apr 2010 18:57, l...@gnu.org (Ludovic Courtès) writes:
>> 2. I think a fluid is still necessary, because a file being >> compiled can do an `include' or `include-from-path', or even >> `open-input-file' in a macro, and all these cases you would want the >> same %file-port-name-canonicalization to take effect. > > Indeed, this one is tricky. > > I still think it’s application-specific, though. How about calling the > fluid, say, %compiler-file-name-canonicalization instead? :-) Are you proposing that all file-opening functions check the %compiler-file-name-canonicalization fluid? Seems better to me for the name of the fluid to be "close" to the function whose behavior it changes. >> 4. The application-level code is nastier if it has to canonicalize, >> because a relative canonicalization > > What do you mean by “relative canonicalization”? > > (I have Glibc’s ‘canonicalize_file_name ()’ in mind, which returns an > absolute path, so I’m confused.) > >> cannot in general be passed to open-input-file. For example >> >> (open-input-file "../../module/ice-9/boot-9.scm") >> >> is not the same as >> >> (open-input-file "ice-9/boot-9.scm") > > Agreed. :-) If you build out-of-source, you might end up with guile-tools compile -o ice-9/boot-9.go ../../modules/ice-9/boot-9.scm So the file you open is "../../modules/ice-9/boot-9.scm", but you want to give it a "relative canonicalization" -- in this case "ice-9/boot-9.scm" is the canonicalization of ../../modules/ice-9/boot-9.scm, *relative* to "../../modules" (or indeed to "/home/wingo/src/guile/modules"). >> So you'd have to do a set-port-filename! on the port, mucking up your >> code -- and how would you decide what to set? In N places you'd have to >> duplicate fport_canonicalize_filename, and you'd probably have to make >> scm_i_relativize_path public. > > I failed to get the transition at “So”. :-) > > What does scm_i_relativize_path do? (It lacks a leading comment, hint > hint. ;-)) You could try a little harder ;-) Perhaps the paragraph above explains; you would have to do: (define (open-input-file* path) (let ((p (open-input-file path))) (case (fluid-ref %file-port-name-canonicalization) ((absolute) (set-port-filename! p (canonicalize-path path))) ((relative) (set-port-filename! p (relativize-path (canonicalize-path path) %load-path)))) p)) which is a bit ugly; e.g. include-from-path would need to do this, as would any third-party equivalent of include-from-path, and even down to the open-file level. Yuk. Andy -- http://wingolog.org/