From: Gregory Novak
Subject: Current Working Directory in SBCL?
Date: 
Message-ID: <m2ejzqh0qo.fsf@ucolick.org>
I apologize to everyone for asking this, but how do I get/set the
current working directory in SBCL?  I found
(extensions:default-directory) for CMUCL, but can't find the
corresponding thing for SBCL.

Thanks,
Greg

From: Gregory Novak
Subject: Re: Current Working Directory in SBCL?
Date: 
Message-ID: <m264l2gvti.fsf@ucolick.org>
Ari Johnson <·········@gmail.com> writes:
> Some Googling got me (truename ".") for SBCL.

Ok, cool, now I can find out what the current directory is.  But I'd
like to be able to do:

(setf (truename ".") #"/whatever")

but that doesn't seem to work.

Juho Snellman <······@iki.fi> writes:
> You can change the working directory with SB-POSIX:CHDIR. There's no
> publically available API for getting the working directory (there's an
> internal one, but I don't recommend using it).

Hmm, I looked there and somehow managed to miss it.  But now I'm
confused:

CL-USER> (truename ".")
#P"/Users/novak/Projects/Lisp/"
CL-USER> (sb-posix:chdir #P"/Users/novak/Projects/")
0
CL-USER> (truename ".")
#P"/Users/novak/Projects/Lisp/"

What gives?

> But there actually aren't many reasons to care about the Unix working
> directory in Lisp. Maybe you're looking for the standard CL variable 
> *DEFAULT-PATHNAME-DEFAULTS* instead?

It depends on what you're trying to do.  If you started Lisp in the
wrong directory (because it's running underneath Emacs) and are trying
to load lisp files from the repl, then you do want to change the
working directory (or at least I did).

Bill Atkins <············@rpi.edu> writes:
>   (setf *default-pathname-defaults* (truename "/dev"))
> or, more concisely:
>   (setf *default-pathname-defaults* #P"/dev")

I could have sworn that I tried this and it didn't work.  That is, the
value of the variable changed but I still wasn't in the directory I
wanted (since I still couldn't load my source files).  But now I just
tried it again and it worked.  I'm losing my mind...

Thanks!
Greg
From: Juho Snellman
Subject: Re: Current Working Directory in SBCL?
Date: 
Message-ID: <slrne4j99u.gqa.jsnell@sbz-30.cs.Helsinki.FI>
Gregory Novak <·····@ucolick.org> wrote:
> CL-USER> (truename ".")
> #P"/Users/novak/Projects/Lisp/"
> CL-USER> (sb-posix:chdir #P"/Users/novak/Projects/")
> 0
> CL-USER> (truename ".")
> #P"/Users/novak/Projects/Lisp/"
> 
> What gives?

The working directory doesn't affect the standard CL pathname
functions on SBCL.

>> But there actually aren't many reasons to care about the Unix working
>> directory in Lisp. Maybe you're looking for the standard CL variable 
>> *DEFAULT-PATHNAME-DEFAULTS* instead?
> 
> It depends on what you're trying to do.  If you started Lisp in the
> wrong directory (because it's running underneath Emacs) and are trying
> to load lisp files from the repl, then you do want to change the
> working directory (or at least I did).

Then you don't care about the working directory, but about *D-P-D* ;-)
The working directory might matter when calling into foreign functions
or starting external programs. But generally not when working with
plain Lisp.

-- 
Juho Snellman
From: Gregory Novak
Subject: Re: Current Working Directory in SBCL?
Date: 
Message-ID: <m2y7xyfcay.fsf@ucolick.org>
Juho Snellman <······@iki.fi> writes:
> The working directory doesn't affect the standard CL pathname
> functions on SBCL.

> ...

> Then you don't care about the working directory, but about *D-P-D* ;-)
> The working directory might matter when calling into foreign functions
> or starting external programs. But generally not when working with
> plain Lisp.

Wow... so CL only cares about *D-P-D*, and (truename ".") reflects
that, while the working directory is affected by (sb-posix:chdir), but
nobody cares about that, except foreign programs.  Is that right?  Now
I don't feel quite so bad about asking the question in the first place...

Thanks,
Greg
From: Frode Vatvedt Fjeld
Subject: Re: Current Working Directory in SBCL?
Date: 
Message-ID: <2h64l2kptf.fsf@vserver.cs.uit.no>
Gregory Novak <·····@ucolick.org> writes:

> Wow... so CL only cares about *D-P-D*, and (truename ".") reflects
> that, while the working directory is affected by (sb-posix:chdir),
> but nobody cares about that, except foreign programs.  Is that
> right?  Now I don't feel quite so bad about asking the question in
> the first place...

In a broader perspective, I suppose this is an instance of the
mismatch between unix's "process scope" for a number of variables
(i.e. per-process variables maintained by the kernel) which make sense
i a C world but seem ridiculously insufficient from a Lisp perspective
where dynamic scope is understood and appreciated.

It's a case of the Right Thing (to lispers) not being the same as the
Least Surprinsing Thing (to "most people"), and I venture to say an
important factor why e.g. Python is so much more popular.

-- 
Frode Vatvedt Fjeld
From: Thomas A. Russ
Subject: Re: Current Working Directory in SBCL?
Date: 
Message-ID: <ymir73nuf7u.fsf@sevak.isi.edu>
Gregory Novak <·····@ucolick.org> writes:

> Ok, cool, now I can find out what the current directory is.  But I'd
> like to be able to do:
> 
> (setf (truename ".") #"/whatever")
> 
> but that doesn't seem to work.

Actually, I doubt you would really want to do that.  If this were to
work, I would expect the effect to be renaming the current working
directory rather than changing it.

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Ari Johnson
Subject: Re: Current Working Directory in SBCL?
Date: 
Message-ID: <m2fyk6wgcy.fsf@hermes.theari.com>
Gregory Novak <·····@ucolick.org> writes:

> I apologize to everyone for asking this, but how do I get/set the
> current working directory in SBCL?  I found
> (extensions:default-directory) for CMUCL, but can't find the
> corresponding thing for SBCL.

Some Googling got me (truename ".") for SBCL.
From: Bill Atkins
Subject: Re: Current Working Directory in SBCL?
Date: 
Message-ID: <87k69iqssh.fsf@rpi.edu>
···@zedat.fu-berlin.de (Stefan Ram) writes:

> Ari Johnson <·········@gmail.com> writes:
>>Some Googling got me (truename ".") for SBCL.
>
>   CLISP:
>
> Y CLISP Copyright (c) Bruno Haible (...)
> [1]> (truename ".")
> #P"C:\\clisp-2.38-win32\\clisp-2.38\\."
> [2]> (exit)
> bye.
>
>   Windows 98:
>
> Microsoft(R) Windows 98
>    (C)Copyright Microsoft Corp 1981-1999.
> C:\WINDOWS\Desktop>truename "."
> C:\WINDOWS\DESKTOP
> C:\WINDOWS\Desktop>exit
>
>   By this, the only difference between Windows 98 and CLISP is,
>   that the commands in CLISP need an additional pair of parentheses. 
>
>

What does this add to the discussion?

-- 

"...and when, another time, I discovered that he considered not
unworthy of reflection in one of those mirrors of absolute truth which
were his writings a remark similar to one which I had had occasion to
make about our friend M. Legrandin, ...then it was suddenly revealed
to me that my own humble existence and the realms of the true were
less widely separated than I had supposed, that at certain points they
actually collided, and in my newfound confidence and joy, I had wept
upon his printed page as in the arms of a long-lost father."
From: Bill Atkins
Subject: Re: Current Working Directory in SBCL?
Date: 
Message-ID: <874q0mqsiq.fsf@rpi.edu>
Gregory Novak <·····@ucolick.org> writes:

> I apologize to everyone for asking this, but how do I get/set the
> current working directory in SBCL?  I found
> (extensions:default-directory) for CMUCL, but can't find the
> corresponding thing for SBCL.
>
> Thanks,
> Greg

  (setf *default-pathname-defaults* (truename "/dev"))

or, more concisely:

  (setf *default-pathname-defaults* #P"/dev")

will probably do what you want.  Both are equivalent.  The variable
*DEFAULT-PATHNAME-DEFAULTS* should (has to?) be set to a pathname
object and not just a string.  Both the TRUENAME functions and the #P
read macro will build a pathname from a string.

hth.

-- 

"...and when, another time, I discovered that he considered not
unworthy of reflection in one of those mirrors of absolute truth which
were his writings a remark similar to one which I had had occasion to
make about our friend M. Legrandin, ...then it was suddenly revealed
to me that my own humble existence and the realms of the true were
less widely separated than I had supposed, that at certain points they
actually collided, and in my newfound confidence and joy, I had wept
upon his printed page as in the arms of a long-lost father."
From: Peter Seibel
Subject: Re: Current Working Directory in SBCL?
Date: 
Message-ID: <m2slo6bbvs.fsf@gigamonkeys.com>
Bill Atkins <············@rpi.edu> writes:

> Gregory Novak <·····@ucolick.org> writes:
>
>> I apologize to everyone for asking this, but how do I get/set the
>> current working directory in SBCL?  I found
>> (extensions:default-directory) for CMUCL, but can't find the
>> corresponding thing for SBCL.
>>
>> Thanks,
>> Greg
>
>   (setf *default-pathname-defaults* (truename "/dev"))
>
> or, more concisely:
>
>   (setf *default-pathname-defaults* #P"/dev")
>
> will probably do what you want.  Both are equivalent.  The variable
> *DEFAULT-PATHNAME-DEFAULTS* should (has to?) be set to a pathname
> object and not just a string.  Both the TRUENAME functions and the #P
> read macro will build a pathname from a string.

SBCL may or may not care, but it's a good habit (because some impls do
care) to end namestrings that are supposed to represent directories
with a /, so:

  (setf *default-pathname-defaults* (truename "/dev/"))

or

  (setf *default-pathname-defaults* #p"/dev/")

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Bill Atkins
Subject: Re: Current Working Directory in SBCL?
Date: 
Message-ID: <877j5iux8w.fsf@rpi.edu>
Peter Seibel <·····@gigamonkeys.com> writes:

> Bill Atkins <············@rpi.edu> writes:
>
>> Gregory Novak <·····@ucolick.org> writes:
>>
>>> I apologize to everyone for asking this, but how do I get/set the
>>> current working directory in SBCL?  I found
>>> (extensions:default-directory) for CMUCL, but can't find the
>>> corresponding thing for SBCL.
>>>
>>> Thanks,
>>> Greg
>>
>>   (setf *default-pathname-defaults* (truename "/dev"))
>>
>> or, more concisely:
>>
>>   (setf *default-pathname-defaults* #P"/dev")
>>
>> will probably do what you want.  Both are equivalent.  The variable
>> *DEFAULT-PATHNAME-DEFAULTS* should (has to?) be set to a pathname
>> object and not just a string.  Both the TRUENAME functions and the #P
>> read macro will build a pathname from a string.
>
> SBCL may or may not care, but it's a good habit (because some impls do
> care) to end namestrings that are supposed to represent directories
> with a /, so:
>
>   (setf *default-pathname-defaults* (truename "/dev/"))
>
> or
>
>   (setf *default-pathname-defaults* #p"/dev/")
>
> -Peter
>
> -- 
> Peter Seibel           * ·····@gigamonkeys.com
> Gigamonkeys Consulting * http://www.gigamonkeys.com/
> Practical Common Lisp  * http://www.gigamonkeys.com/book/

Good to know, thanks.

Bill
From: Juho Snellman
Subject: Re: Current Working Directory in SBCL?
Date: 
Message-ID: <slrne4j3bf.g21.jsnell@sbz-30.cs.Helsinki.FI>
Gregory Novak <·····@ucolick.org> wrote:
> I apologize to everyone for asking this, but how do I get/set the
> current working directory in SBCL?  I found
> (extensions:default-directory) for CMUCL, but can't find the
> corresponding thing for SBCL.

You can change the working directory with SB-POSIX:CHDIR. There's no
publically available API for getting the working directory (there's an
internal one, but I don't recommend using it).

But there actually aren't many reasons to care about the Unix working
directory in Lisp. Maybe you're looking for the standard CL variable 
*DEFAULT-PATHNAME-DEFAULTS* instead?

-- 
Juho Snellman
From: Julian Squires
Subject: Re: Current Working Directory in SBCL?
Date: 
Message-ID: <87fyjsnwpz.fsf@cipht.net>
Gregory Novak <·····@ucolick.org> writes:
> I apologize to everyone for asking this, but how do I get/set the
> current working directory in SBCL?  I found
> (extensions:default-directory) for CMUCL, but can't find the
> corresponding thing for SBCL.

Depending on what you're actually trying to do, and as long as you're
not opposed to using a non-default library, you might consider trying
Osicat, which allows you to do:

CL-USER> (osicat:current-directory)
#P"/home/julian/"
CL-USER> (setf (osicat:current-directory) "/home")
"/home"
CL-USER> (osicat:current-directory)
#P"/home/"

See <http://www.common-lisp.net/project/osicat>.

Cheers.

-- 
Julian Squires