Passing Global Variables Urgh.
- From: landspeedrecord <landspeedrecord@xxxxxxxxx>
- Date: Wed, 29 Aug 2007 23:28:28 -0000
Total newbie question....
First off... I know I am not supposed to use global variables in Lisp,
however...
Can anyone explain to me why the following bit of code doesn't work?
I don't get it and I think it is because there is something very
fundamental I do not understand about Lisp.
CM> (defvar *x* "blargh")
*X*
CM> *x*
"blargh"
CM> (defun test2 (x)
(setq x "orrgoaarghhh"))
TEST2
CM> (test2 *x*)
"orrgoaarghhh"
CM> *x*
"blargh"
My only guess is that the function "test2" gets passed a copy of the
global variable that is exists inside the function "test2". But isn't
the whole point of Defvar & Defparameter to create a global variable
that can be accessed from anywhere? If a copy of a global variable is
always passed into functions what good is a global variable?
Now I could write "test2" so that it was:
(defun test2 ()
(setq *x* "orrgoaarghhh"))
but that isn't the same as passing the global variable.
I just don't get it. Urgh???
.
- Follow-Ups:
- Re: Passing Global Variables Urgh.
- From: Ralf Mattes
- Re: Passing Global Variables Urgh.
- From: John Thingstad
- Re: Passing Global Variables Urgh.
- From: Scott Burson
- Re: Passing Global Variables Urgh.
- From: JK
- Re: Passing Global Variables Urgh.
- From: Geoff Wozniak
- Re: Passing Global Variables Urgh.
- From: andrea
- Re: Passing Global Variables Urgh.
- From: Rainer Joswig
- Re: Passing Global Variables Urgh.
- Prev by Date: Floyd Warshall
- Next by Date: Re: Passing Global Variables Urgh.
- Previous by thread: Floyd Warshall
- Next by thread: Re: Passing Global Variables Urgh.
- Index(es):
Relevant Pages
|