Re: enough-namestring doesn't work?

Raymond Toy <[email protected]>
Newsgroups gmane.lisp.gcl.devel
Message-ID <[email protected]>
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 <[email protected]> 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?
>>
>> ​
>>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.