From: Zhang Le
Subject: make-pathname with relative directory?
Date: 
Message-ID: <4bfcab1f.0411281346.4b42813c@posting.google.com>
Hi,
  I want to open a file "output/model.3" under current directory. But
under clisp (make-pathname :name "model.3" :directory "output") gives
me #P"/output/model.3" which is an absolute directory. So how to get
make-pathname work for relative directory?

  Thanks.

Zhang Le

From: Thomas F. Burdick
Subject: Re: make-pathname with relative directory?
Date: 
Message-ID: <xcv653pljlt.fsf@conquest.OCF.Berkeley.EDU>
·········@sneakemail.com (Zhang Le) writes:

> Hi,
>   I want to open a file "output/model.3" under current directory. But
> under clisp (make-pathname :name "model.3" :directory "output") gives
> me #P"/output/model.3" which is an absolute directory. So how to get
> make-pathname work for relative directory?

  make-pathname :name "file" :type "type"
  		:directory '(:relative "path" "to" "output"))

will generally produce something like: #P"path/to/output/file.type"

However, you might also want to check out merge-pathnames:

  (defvar *output-path* (make-pathname :directory '(:relative "output")))

...

  (let ((filename (make-pathname :name "model" :type "3")))
    (merge-pathnames filename :defaults *output-path*))

=> #P"output/model.3"
From: Zhang Le
Subject: Re: make-pathname with relative directory?
Date: 
Message-ID: <4bfcab1f.0411291210.5676b9a1@posting.google.com>
···@conquest.OCF.Berkeley.EDU (Thomas F. Burdick) wrote in message 
> However, you might also want to check out merge-pathnames:
> 
>   (defvar *output-path* (make-pathname :directory '(:relative "output")))
> 
> ...
> 
>   (let ((filename (make-pathname :name "model" :type "3")))
>     (merge-pathnames filename :defaults *output-path*))
> 
> => #P"output/model.3"
After trying several methods (and the combinations of them), I finally
found the easiest way to open a file is to pass the filename to (open)
directly without (make-pathname), and it works:
Break 1 [1]> (open "output/model.3")
#<INPUT BUFFERED FILE-STREAM CHARACTER #P"output/model.3" @1>
Break 1 [1]>

Zhang Le
From: Kenny Tilton
Subject: Re: make-pathname with relative directory?
Date: 
Message-ID: <kcNqd.20784$ld2.6486239@twister.nyc.rr.com>
Zhang Le wrote:

> ···@conquest.OCF.Berkeley.EDU (Thomas F. Burdick) wrote in message 
> 
>>However, you might also want to check out merge-pathnames:
>>
>>  (defvar *output-path* (make-pathname :directory '(:relative "output")))
>>
>>...
>>
>>  (let ((filename (make-pathname :name "model" :type "3")))
>>    (merge-pathnames filename :defaults *output-path*))
>>
>>=> #P"output/model.3"
> 
> After trying several methods (and the combinations of them), I finally
> found the easiest way to open a file is to pass the filename to (open)
> directly without (make-pathname), and it works:
> Break 1 [1]> (open "output/model.3")
> #<INPUT BUFFERED FILE-STREAM CHARACTER #P"output/model.3" @1>
> Break 1 [1]>

It works? I am happy for you. But you were about two seconds away from 
understanding simple pathname usage. Which you will need when you get to 
a bigger project.

But I know the feeling. I am leaving all sorts of "working debris" 
behind as I struggle to port cells-gtk from the CLisp FFI to the much 
less capable (but much more portable) UFFI.

It works?! Great! Next backtrace!

kenny

-- 
Cells? Cello? Celtik?: http://www.common-lisp.net/project/cells/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
From: Kenny Tilton
Subject: Re: make-pathname with relative directory?
Date: 
Message-ID: <cLrqd.20710$ld2.6153966@twister.nyc.rr.com>
Zhang Le wrote:
> Hi,
>   I want to open a file "output/model.3" under current directory. But
> under clisp (make-pathname :name "model.3" :directory "output") gives
> me #P"/output/model.3" which is an absolute directory. So how to get
> make-pathname work for relative directory?

Try:

     :directory '(:relative "output")

When you want absolute:

     :directory '(:absolute "data" "output")

...for example. Looks like :absolute is the default. Don't know, really.

kt
From: Zhang Le
Subject: Re: make-pathname with relative directory?
Date: 
Message-ID: <4bfcab1f.0411290327.6a8cba14@posting.google.com>
Kenny Tilton <·······@nyc.rr.com> wrote in message 
> Try:
> 
>      :directory '(:relative "output")
> 
> When you want absolute:
> 
>      :directory '(:absolute "data" "output")
> 
Thanks for the hint, (make-pathname :name "model.3" :directory
'(:relative "output")) now works. But I encounter another problem when
using a variable name for dir name:
(setf dir "output")
(make-pathname :name "model.3" :directory '(:relative dir))
And I got (from clisp):
** - Continuable Error
MAKE-PATHNAME: illegal :DIRECTORY argument (:RELATIVE DIR)
...

Any tips?

Zhang Le
From: Svein Ove Aas
Subject: Re: make-pathname with relative directory?
Date: 
Message-ID: <cof207$ftd$3@services.kq.no>
Zhang Le wrote:

> Kenny Tilton <·······@nyc.rr.com> wrote in message
>> Try:
>> 
>>      :directory '(:relative "output")
>> 
>> When you want absolute:
>> 
>>      :directory '(:absolute "data" "output")
>> 
> Thanks for the hint, (make-pathname :name "model.3" :directory
> '(:relative "output")) now works. But I encounter another problem when
> using a variable name for dir name:
> (setf dir "output")
> (make-pathname :name "model.3" :directory '(:relative dir))
> And I got (from clisp):
> ** - Continuable Error
> MAKE-PATHNAME: illegal :DIRECTORY argument (:RELATIVE DIR)
> ...
> 
> Any tips?
> 
That's a variable name, not a variable.
Try (list :relative dir) instead, and read up on quote.
From: Kenny Tilton
Subject: Re: make-pathname with relative directory?
Date: 
Message-ID: <IGFqd.20754$ld2.6393090@twister.nyc.rr.com>
Zhang Le wrote:

> Kenny Tilton <·······@nyc.rr.com> wrote in message 
> 
>>Try:
>>
>>     :directory '(:relative "output")
>>
>>When you want absolute:
>>
>>     :directory '(:absolute "data" "output")
>>
> 
> Thanks for the hint, (make-pathname :name "model.3" :directory
> '(:relative "output")) now works. But I encounter another problem when
> using a variable name for dir name:
> (setf dir "output")
> (make-pathname :name "model.3" :directory '(:relative dir))
> And I got (from clisp):
> ** - Continuable Error
> MAKE-PATHNAME: illegal :DIRECTORY argument (:RELATIVE DIR)
> ...
> 
> Any tips?

Yes. Slow down. :) Your success with hairy things like pathnames is 
being impeded by your weakness in elementary Lisp concepts.

Mind you, I share your "damn the torpedos" approach to learning a new 
language, but I also break down and read a few tutorial chapters when 
the simple stuff starts costing me hours of frustration.

The immediate answer is that ' is short for QUOTE and means, in this 
case, "do not use the value of the variable DIR". (Quoting a list such 
as '(:relative dir) quotes everything in the list.)

Now Svein already told you about (list...), but since you like charging 
ahead, here is a fun trick which will get you ready for macros:

    (let ((dir "output")) `(:relative ,dir))

That is a backquote up there. The comma does what you were hoping for: 
"I know I said QUOTE, but right here I want you to evaluate at run-time 
and use that". This is mad handy when you want a mostly literal list 
with a little runtime data spliced in.

kenny



> 
> Zhang Le

-- 
Cells? Cello? Celtik?: http://www.common-lisp.net/project/cells/
Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film
From: Svein Ove Aas
Subject: Re: make-pathname with relative directory?
Date: 
Message-ID: <cofcpl$5o$1@services.kq.no>
Kenny Tilton wrote:

>     (let ((dir "output")) `(:relative ,dir))
> 
> That is a backquote up there. The comma does what you were hoping for:
> "I know I said QUOTE, but right here I want you to evaluate at run-time
> and use that". This is mad handy when you want a mostly literal list
> with a little runtime data spliced in.
> 

Note that in my code, (list :relative dir), :relative was evaluated. In this
code it isn't, but the result is the same.

This is because a keyword, that being any symbol of the form ":name", always
evaluates to itself. This is very, very handy; it lets you pass around what
amounts to bits of text, but without the overhead of such text.

It also has uses in cross-package calls and functions with optional
parameters, but you'll get to that later.