gcl-devel
[Top][All Lists]
Advanced

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

Re: enough-namestring doesn't work?


From: Raymond Toy
Subject: Re: enough-namestring doesn't work?
Date: Mon, 29 May 2023 09:33:29 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1


On 5/29/23 08:56, Camm Maguire wrote:
Greetings, and thanks for your feedback!

(enough-namestring #P"/a/b/c/d.txt" #P"/a/b/c/") -> "d.txt"

This is right, but I think getting the directory components is important too.  For the example I gave, the answer from gcl is not the shortest reasonable string that satisfies the criterion.  The shortest is "c/d.txt".

For the particular case I was looking at (from maxima), I don't have to use enough-namestring because the pathnames I have are from directory so it's easy to strip of the leading parts (assuming directory didn't follow symlinks to get a totally different directory).  But enough-namestring seems to be the natural way to strip off the leading parts of the path.


gcl's version does not unpack the directory component into segments but
just compares the pathanme components with the default as whole units:

(DEFUN ENOUGH-NAMESTRING
        (X &OPTIONAL (DEF *DEFAULT-PATHNAME-DEFAULTS*) &AUX
           (PX (PATHNAME X)) (PDEF (PATHNAME DEF)))
   (DECLARE (OPTIMIZE (SAFETY 1)))
   (CHECK-TYPE X PATHNAME-DESIGNATOR)
   (CHECK-TYPE DEF PATHNAME-DESIGNATOR)
   (NAMESTRING
       (MAKE-PATHNAME :HOST
           (LET ((K (PATHNAME-HOST PX)))
             (UNLESS (EQUAL K (PATHNAME-HOST PDEF)) K))
           :DEVICE
           (LET ((K (PATHNAME-DEVICE PX)))
             (UNLESS (EQUAL K (PATHNAME-DEVICE PDEF)) K))
           :DIRECTORY
           (LET ((K (PATHNAME-DIRECTORY PX)))
             (UNLESS (EQUAL K (PATHNAME-DIRECTORY PDEF)) K))
           :NAME
           (LET ((K (PATHNAME-NAME PX)))
             (UNLESS (EQUAL K (PATHNAME-NAME PDEF)) K))
           :TYPE
           (LET ((K (PATHNAME-TYPE PX)))
             (UNLESS (EQUAL K (PATHNAME-TYPE PDEF)) K))
           :VERSION
           (LET ((K (PATHNAME-VERSION PX)))
             (UNLESS (EQUAL K (PATHNAME-VERSION PDEF)) K)))))

It seems this is compliant given the spec:

=============================================================================
enough-namestring returns an abbreviated namestring that is just sufficient to 
identify the file named by pathname when considered relative to the defaults. 
It is required that

  (merge-pathnames (enough-namestring pathname defaults) defaults)
==  (merge-pathnames (parse-namestring pathname nil defaults) defaults)

in all cases, and the result of enough-namestring is the shortest reasonable 
string that will satisfy this criterion.

It is not necessarily possible to construct a valid namestring by concatenating 
some of the three shorter namestrings in some order.
=============================================================================

Perhaps this could be improved.

Take care,

Raymond Toy <toy.raymond@gmail.com> writes:

I tried the followin: (enough-namestring #P"/a/b/c/d.txt" #P"/a/b/"). I was expecting 
"c/d.txt". But gcl 2.6.13 release returns “/a/b/c/d.txt”. I actually can’t find any example where 
enough-namestring produces anything other than the namestring for the
first arg.

How do I invoke enough-namestring to produce what I want, like other lisps do?

​




reply via email to

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