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