From: Trent Buck
Subject: make-pathname :directory
Date: 
Message-ID: <20041126045616.6cb57769@harpo.marx>
I've started a writing something in Lisp now, so expect lots of *dumb*
questions :-)

I'm trying to point a global variable at $HOME/foo.lisp.  I can't work
out how the :directory parameter of (make-pathname) works.  The
hyperspec say that it takes a `valid pathname directory', but my
textbook (Graham's ANSI CL) doesn't seem to have an example.  Can
someone explain how I'm supposed to do it?

Here's my (incorrect) draft:

	(defparameter *output-file* 
	  (make-pathname :directory (list "home" "twb")	;wrong
	                 :name "foo.lisp"))

	(defun foo (text)
	  (assert (stringp text))
	  (with-open-file (output-stream *output-file* 
	                                 :direction :output
	                                 :if-exists :append)
			  (format output-stream "hello world~%")))


I'm using CMUCL (and GCL and Clisp).

-trent

From: Peter Seibel
Subject: Re: make-pathname :directory
Date: 
Message-ID: <m3r7mherd2.fsf@javamonkey.com>
Trent Buck <··············@bigpond.com> writes:

> I've started a writing something in Lisp now, so expect lots of *dumb*
> questions :-)
>
> I'm trying to point a global variable at $HOME/foo.lisp.  I can't work
> out how the :directory parameter of (make-pathname) works.  The
> hyperspec say that it takes a `valid pathname directory', but my
> textbook (Graham's ANSI CL) doesn't seem to have an example.  Can
> someone explain how I'm supposed to do it?
>
> Here's my (incorrect) draft:
>
> 	(defparameter *output-file* 
> 	  (make-pathname :directory (list "home" "twb")	;wrong
> 	                 :name "foo.lisp"))

The :directory element is always a list starting with :absolute or
:relative. Also, the name and type are separate components. So you
want:

  (make-pathname :directory '(:absolute "home" "twb") :name "foo" :type "lisp")


-Peter


-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Zach Beane
Subject: Re: make-pathname :directory
Date: 
Message-ID: <m3is7ta8jt.fsf@unnamed.xach.com>
Peter Seibel <·····@javamonkey.com> writes:

> Trent Buck <··············@bigpond.com> writes:
>
>> I've started a writing something in Lisp now, so expect lots of *dumb*
>> questions :-)
>>
>> I'm trying to point a global variable at $HOME/foo.lisp.  I can't work
>> out how the :directory parameter of (make-pathname) works.  The
>> hyperspec say that it takes a `valid pathname directory', but my
>> textbook (Graham's ANSI CL) doesn't seem to have an example.  Can
>> someone explain how I'm supposed to do it?
>>
>> Here's my (incorrect) draft:
>>
>> 	(defparameter *output-file* 
>> 	  (make-pathname :directory (list "home" "twb")	;wrong
>> 	                 :name "foo.lisp"))
>
> The :directory element is always a list starting with :absolute or
> :relative. Also, the name and type are separate components. So you
> want:
>
>   (make-pathname :directory '(:absolute "home" "twb") :name "foo" :type "lisp")

Since the OP mentioned $HOME, USER-HOMEDIR-PATHNAME might be useful
too:

   (make-pathname :name "foo" :type "lisp" :defaults (user-homedir-pathname))

   (merge-pathnames #p"foo.lisp" (user-homedir-pathname))

Zach
From: Trent Buck
Subject: Re: make-pathname :directory
Date: 
Message-ID: <20041126051531.279bc360@harpo.marx>
Quoth Peter Seibel on or about 2004-11-25:
> The :directory element is always a list starting with :absolute or
> :relative. Also, the name and type are separate components. So you
> want:
> 
>   (make-pathname :directory '(:absolute "home" "twb") :name "foo" :type "lisp")

Excellent, thank you.

-t