Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strange pathname?

* (make-pathname :name "cgi-bin/")
#P"cgi-bin/"
* (merge-pathnames "nav.py" #P"cgi-bin/")
#P"cgi-bin/nav.py"    ; **it is ok**
* (merge-pathnames "nav.py" (make-pathname :name "cgi-bin/"))
#P"nav.py"            ; why ?

*(defvar bp #P"/media/E/myapp/cgi-bin/")
* bp
#P"/media/E/myapp/cgi-bin/")
* (merge-pathnames "nav.py" bp)
#P"nav.py"            ; why ?
* (merge-pathnames "nav.py" #P"/media/E/myapp/cgi-bin/")
#P"/media/E/myapp/cgi-bin/nav.py"    ; **it is ok**

I am using sbcl-1.0.54.

Any suggestion is appreciated !

like image 399
z_axis Avatar asked Oct 10 '22 01:10

z_axis


1 Answers

A pathname is a structure that represents a pathname using components, like drive, host, directory, name, etc. See here for more details.

You construct a pathname using make-pathname function with :directory, :name and other keywords, and the function returns an object of type pathname:

CL-USER> (defvar p (make-pathname :directory '(:absolute "home" "test" "docs")))
CL-USER> #P"/home/test/docs/"

The function merge-pathnames as documented here, completes the missing components of the pathname specified with the ones from default-pathname:

CL-USER> (merge-pathnames p "tada.txt")
CL-USER> #P"/home/test/docs/tada.txt"

Edit: it doesn't work for you because you are constructing a pathname with :name and that specifies the name of the file (without extension or :type). So when you call merge-pathnames it doesn't find a missing component in its pathname, because "cgi-bin/" is specified as :name (the filename), and you already got a filename in "nav.py".

like image 72
sbenitezb Avatar answered Oct 13 '22 11:10

sbenitezb