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

Issue: PATHNAME-EXTENSIONS (Version 1)



Here's a made-up example of the kind I was imagining:

(DEFUN TRANSLATE-LOGICAL-PATHNAME (LPATHNAME)
  (MULTIPLE-VALUE-BIND (LHOST LDEVICE LDIR LNAME LTYPE LVERSION)
      (PARSE-LOGICAL-PATHNAME LPATHNAME)
    (MULTIPLE-VALUE-BIND (PHOST PDEVICE PDIR PNAME PTYPE PVERSION)
        (TRANSLATE-PATHNAME-COMPONENTS LHOST LDEVICE LDIR LNAME LTYPE LVERSION)
      (LET ((PHYSICAL-PATHNAME (MAKE-PATHNAME :HOST PHOST ...)))
        (UNLESS (COMMON-PATHNAME-P PHYSICAL-PATHNAME)
          (CERROR "Use ~*~A anyway."
		  "The result of translating pathname ~A to a physical pathname~
		 ~%resulted in a valid physical pathname, ~A,~
                 ~%but that pathname has special meaning to host ~A which may~
		 ~%not have been what was intended."
	          LPATHNAME PHYSICAL-PATHNAME PHOST))))))

I don't think I have a specific example around, but I remember I used to worry
about this a lot in Macsyma, because LispM Macsyma does cross-host file searches
by mixing and matching file syntaxes gotten from here and there. I used to worry
it would construct pathnames that were magic in some way and do something weird.
If I could have put in an error check here and there, I'd have felt a bit more 
comfortable.

Also, CLtL's spec gives so much leeway allowing "implementation-dependent" things
all over the place in pathnames, that I just figured that it would be easier for
users who want to assume the "nice" values are present to just guard simple-minded
code with

 (COND ((COMMON-PATHNAME-P PATHNAME)
        ... code that assumes pathnames don't contain hairy junk ...)
       (T
        (ERROR "Pathname ~S was more complex than I expected." PATHNAME)))

As clumsy as this error seems, it's probably more informative than the
LENGTH got bad argument or whatever that you'd get instead if you wrote the
same code unguarded. Seems like that would provide at least the opportunity
for fault-tolerant code without giving up the ability to do fast prototyping.