guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: port-filename and path canonicalization


From: Andy Wingo
Subject: Re: port-filename and path canonicalization
Date: Tue, 20 Apr 2010 11:42:58 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux)

Hi :)

On Tue 20 Apr 2010 01:12, address@hidden (Ludovic Courtès) writes:

> Andy Wingo <address@hidden> writes:
>
>> I recently added a global fluid, %file-port-name-canonicalization, which
>> defaults to #f. But if it's 'absolute, the port name of a file port will
>> be canonicalized to the absolute path; or, if it's 'relative, the port
>> name is the canonical name of the file, relative to the %load-path, or
>> the file name as given otherwise.
>>
>> The intention was to allow the user to control (port-filename P), so
>> that the user could find e.g. the absolute path corresponding to that
>> port at the time that it was made.
>
> My feeling is that ports shouldn’t have to deal with paths because
> that’s a separate concern.  The %file-port-name-canonicalization fluid
> seems like an inelegant hack to me.
>
> When applications have special requirements about paths, then it should
> be up to the application logic to deal with that.

I am inclined to agree. A few complications cloud my view, though.

1. While ports do not have anything to do with file names / paths,
*file* ports certainly do -- because not only do they use the given path
to open the file, they set that path as the port's filename, providing
the only means for reverse-mapping ports to filenames (which is the end
goal here, reverse-mapping objects to filenames).

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.

3. The only correct time to do a path canonicalization is when the file
is opened, because at another time, you might not be in the same current
directory, so relative paths would resolve incorrectly.

4. The application-level code is nastier if it has to canonicalize,
because a relative canonicalization 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")

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.


When I realized all of that I decided to go with the minimal correct
solution, though it is a bit hacky. Applications are still free to do
their own thing, as %file-port-name-canonicalization defaults to #f, but
the useful 'absolute and 'relative behaviors are more convenient and
robust.

I'd be happy to have some cleaner solution, though. Do you have any
ideas?

Cheers,

Andy
-- 
http://wingolog.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]