opening it up with Common Lisp

Favorite weblogs

Lisp Related

Bill Clementson

Finding Lisp


Planet Lisp



Talking Points Memo

This Modern World

Working for Change

Other home


Recent Readings

Book review: Darwinia
Reviewed: Friday, August 11, 2006

Summer reading: Spin
Reviewed: Saturday, August 5, 2006

Reviewed: Tuesday, July 18, 2006

the Omnivoire's Delimma
Reviewed: Wednesday, July 12, 2006

the Golem's Eye
Reviewed: Wednesday, May 31, 2006


Monday, February 6, 2006

I couldn't immediately think of an existing way to determine the physical pathname directory separator in Lisp so I wrote this:

(defun physical-pathname-directory-separator ()
  (let* ((directory-1 "foo")
         (directory-2 "bar")
         (pn (namestring
                :host nil
                :directory `(:absolute ,directory-1 ,directory-2)
                :name nil
                :type nil))))
         (foo-pos (search directory-1 pn :test #'char-equal))
         (bar-pos (search directory-2 pn :test #'char-equal)))
    (subseq pn (+ foo-pos (length directory-1)) bar-pos)))

This works on my Mac under Digitool's MCL, SBCL, CLISP and Allegro. I still don't have a Windows box to test upon but maybe some happy reader can contribute! Alternatively, some unhappy reader can tell me the 100-ways in which the code above is wrong <smile>.

(BTW, I assume in the code that the delimiter could be a string with length greater than one. It's probably always going to be a single character which would make my life slightly more easy... Does anyone know of a file system that uses multi-character delimiters between directories? How about something that would disallow such a scheme?).

Update: Peter Seibel reminds me that I should probably be using #'char-equal, instead of #string-equal in my calls to search. Also, I have reports of success under SBCL and Windows 2000. I'll take that as a success.


Home | About | Quotes | Recent | Archives

Copyright -- Gary Warren King, 2004 - 2006