From: Peter Seibel
Subject: Environment variables? (Unix)
Date: 
Message-ID: <3nphgo$ha8@kadath.zeitgeist.net>
Is it possible to access Unix environment variables in Common Lisp. I
looked through CLtL2 and couldn't quite find anything that made it clear
to me. If so how does one access them. Or to be more straightforward,
what I'm trying to do is deal with CGI-BIN output which puts stuff in the
environment variables. I'm neither a Lisp nor Unix guru so this question
may not be phrased quite right but hopefully you get the gist of it.

Thanks,
Peter Seibel


--------------------------------------------------------
Peter Seibel                    Mother Jones Interactive
······@mojones.com               http://www.mojones.com/
--------------------------------------------------------

From: Erik Naggum
Subject: Re: Environment variables? (Unix)
Date: 
Message-ID: <19950428T113646Z.enag@naggum.no>
[Peter Seibel]

|   Is it possible to access Unix environment variables in Common Lisp.

only on Unix implementations.

|   I looked through CLtL2 and couldn't quite find anything that made it
|   clear to me.

system-dependent issues wouldn't be described in CLtL2.

|   If so how does one access them.

well, first you need find the function.  (apropos "getenv") would be a
start.  (list-all-packages) will list all packages, and you may be able to
focus apropos printout if you limit it to a particular package, as in
(apropos "environment" :extensions).

unfortunately, the three Lisps that I just tested on have not agreed on how
to do it.  here's a unified version

(defun get-environment-variable (var)
  "Return the value of environment variable VAR, or NIL if none."
  (declare (string var))
  (prog1
    #+(and :unix :cmu17) (cdr (assoc (intern var :keyword) *environment-list*))
    #+(and :unix :kcl)   (system:getenv var)	;also AKCL, GCL
    #+(and :unix :clisp) (system::getenv var)
    nil))

can others add to this for their implementation?  it would be nice to have
a fully portable function among Unix systems.

#<Erik>
--
sufficiently advanced political correctness is indistinguishable from sarcasm
From: Simon Brooke
Subject: Re: Environment variables? (Unix)
Date: 
Message-ID: <D7u73A.7qp@rheged.dircon.co.uk>
In article <·····················@naggum.no>,
Erik Naggum  <····@naggum.no> wrote:
>Peter Seibel
>
>|   Is it possible to access Unix environment variables in Common Lisp.
>
>only on Unix implementations.

(...)

>unfortunately, the three Lisps that I just tested on have not agreed on how
>to do it.  here's a unified version
>
>(defun get-environment-variable (var)
>  "Return the value of environment variable VAR, or NIL if none."
>  (declare (string var))
>  (prog1
>    #+(and :unix :cmu17) (cdr (assoc (intern var :keyword) *environment-list*))
>    #+(and :unix :kcl)   (system:getenv var)	;also AKCL, GCL
>    #+(and :unix :clisp) (system::getenv var)
>    nil))
>

Wouldn't it be nicer simply to write a function or macro 'getenv' (one
arg, a symbol, returns a string) for each CL implementation, and
politely suggest to each CL vendor that they adopt this format? After
all, the number of us who are still running LisP down to the hardware
is reducing :-< and most operating systems in current use (not just
UN*X) have a concept of 'environment variables'.

After all, as Erik says,

>it would be nice to have
>a fully portable function among Unix systems.



-- 
------- ·····@rheged.dircon.co.uk (Simon Brooke)

	;; When your hammer is C++, everything begins to look like a thumb.
From: Keith M. Corbett
Subject: Re: Environment variables? (Unix)
Date: 
Message-ID: <KMC.95May1215230@sfs3.specialform.com>
In article <·····················@naggum.no> Erik Naggum <····@naggum.no> writes:

>can others add to this for their implementation?  it would be nice to have
>a fully portable function among Unix systems.

GETENV can be defined for any decent DOS / Windows LISP
implementation.  This works in Allegro CL for Windows:

	#+aclpc (acl:getenv var)

--
Keith M. Corbett             ···@specialform.com
Special Form Software        +1 617 596 7021
From: Pete Halverson
Subject: Re: Environment variables? (Unix)
Date: 
Message-ID: <pch-2804950826220001@m142.mystech.com>
In article <··········@kadath.zeitgeist.net>, Peter Seibel
<······@mojones.com> wrote:

> Is it possible to access Unix environment variables in Common Lisp. I
> looked through CLtL2 and couldn't quite find anything that made it clear
> to me. If so how does one access them. Or to be more straightforward,
> what I'm trying to do is deal with CGI-BIN output which puts stuff in the
> environment variables. I'm neither a Lisp nor Unix guru so this question
> may not be phrased quite right but hopefully you get the gist of it.

You were unsuccessful because there's nothing that says Common Lisp has to
be running under Unix -- why should someone running MCL on a Macintosh or
Genera on a Symbolics care about Unix environment variables?   Typically,
however, a particular *implementation* of Common Lisp for Unix will
provide extensions to provide this OS-dependent functionality. 
Unfortunately, since you don't say whose CL implemenation you're using
(Lucid? Franz? Harlequin? Gnu?) it's kind of hard to provide specifics.

  - Check the documentation provided by your Lisp vendor.  Environment
variable access is often buried somewhere in the discussions about
"foreign function" calls.  

  - Search the vendor's extension package for obvious symbols. e.g. in
Harlequin Lispworks, try

      (apropos "GETENV" :LW)
      (apropos "ENV" :LW)

Lucid's extension package is :LCL, Franz's is :EXCL, dunno about Gnu.

pch