February 26, 2002
Pitman on Pathnames

I need to memorize Kent Pitman's recommendation for constructing pathnames:

  Certainly when making a file FOO.LISP from another, you should
  do:

  (make-pathname
    :name "FOO" :type "LISP" :version nil
    :host      (pathname-host      pathname1 :case :common)
    :device    (pathname-device    pathname1 :case :common)
    :directory (pathname-directory pathname1 :case :common)
    :case :common)

  or

  (make-pathname :name "FOO" :type "LISP" :version nil
                 :defaults pathname1 :case :common)

Actually I already knew this. Well, that is, I knew the first way, but found it so verbose that it felt wrong, even though I knew it was right. I forgot about the second, shorter method using :defaults. It is now my favorite new Lisp idiom.

Kent goes on to say

  A good rule of thumb, I claim, is to always use :case :common.
  I can't stand that it is not the default, but since it is, you
  must always make it explicit.  And don't get lazy about using
  it on the accessors, or you will compose stupid-looking
  filenames.  The algebra decomposing and recomposing filenames
  only comes out right if you consistently use :case :common
  everywhere.

On accessors too!? This, I cannot bear. It's hideous. I will have to live with the fact that I am a lazy, sloppy programmer who chooses to write less portable code than I could.

I remember when I first realized from reading CLTL2 that one should use :case :common, and that under Unix, e.g., one needed to write pathname components with exactly the opposite case of the actual files. It was shocking not only because it was kind of ridiculous, but also because it seemed pretty important for achieving portability and yet I had never heard anyone mention it. Which was, of course, because none of the code I saw, written by people at both the University of Chicago and Northwestern, people who knew lisp very well, actually did that.

Frankly, I don't think it matters very much. I'm satisfied using :case :local and mostly lower case filenames, because, really, that is how at least 99.9% of the machines on the planet do things.

No, I don't find that a very satisfying justification either. It's the Perl mindset, not the typical lisp way of doing things right. But haven't you ever run into a bug in a library or API or language implementation that you knew how to work around, but the bug was so lame and the workaround was so aesthetically offensive that you just couldn't force yourself to write the workaround code?

Posted by jjwiseman at February 26, 2002 01:10 AM
Comments

Er, I don't know what I was thinking exactly. make-pathname with :defaults or merge-pathnames, those are obvious. And yet I am sure for some reason I've found myself in a situation where I had to the the more verbose component-by-component construction and couldn't use merge-pathnames. Well, even if I remember correctly, I was probably constrained to work within some already-broken code or something.

Posted by: jjwiseman on February 26, 2002 12:29 PM
Post a comment
Name:


Email Address:


URL:




Unless you answer this question, your comment will be classified as spam and will not be posted.
(I'll give you a hint: the answer is “lisp”.)

Comments:


Remember info?