Re: enough-namestring doesn't work?

Camm Maguire <[email protected]>
Newsgroups gmane.lisp.gcl.devel
Message-ID <[email protected]>
Greetings, and thanks for your feedback!

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

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?
>
> ​ 
>

-- 
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah
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.