From: stevenlien
Subject: How to create a global variable without using setq or set??
Date: 
Message-ID: <5sLj9.91161$8b1.2645@news01.bloor.is.net.cable.rogers.com>
Is there any other way to create global variable??.....
I can't use setq because my prof told me that setq must place at the global
level.
I can't put setq under any function.......but i just can't think of any
other
function can do that....

ie (defun afunction (name value)  (setq name value)) is not valid......

Any help will be appreciated...
Thank you...

From: Vassil Nikolov
Subject: Re: How to create a global variable without using setq or set??
Date: 
Message-ID: <f34a0f4f.0209232034.dd91473@posting.google.com>
"stevenlien" <··········@yahoo.com> wrote in message news:<····················@news01.bloor.is.net.cable.rogers.com>...
> Is there any other way to create global variable??.....
               ^^^^^

Look up DEFVAR.  (You can ignore DEFPARAMETER for now.)

SETQ or SET do not create variables, so your question would
have sounded better without `other.'

By the way, a single dot usually works better at the end
of a sentence than several dots.

---Vassil.
From: Barry Margolin
Subject: Re: How to create a global variable without using setq or set??
Date: 
Message-ID: <5MNj9.20$Wn3.3008@paloalto-snr1.gtei.net>
In article <····················@news01.bloor.is.net.cable.rogers.com>,
stevenlien <··········@yahoo.com> wrote:
>Is there any other way to create global variable??.....

DEFVAR is the usual way.

>I can't use setq because my prof told me that setq must place at the global
>level.

This is not correct.  SETQ can and is used at all levels of programs.  E.g.

(defun do-stuff (a b)
  (let ((sum (+ a b)))
    (setq sum (* sum sum))
    sum))

>I can't put setq under any function.......but i just can't think of any
>other
>function can do that....
>
>ie (defun afunction (name value)  (setq name value)) is not valid......

This just sets the local variable NAME.  Functions are called by value, so
they can't change the values of the variables that are used in the caller.
If you need something that can work like that, you should write a macro,
but I suspect you haven't gotten to that point in the class yet.

You can use SET or SETF of SYMBOL-VALUE, but this requires that you pass
a symbol to AFUNCTION.

(defun afunction (name value)
  (setf (symbol-value name) value))

(afunction 'foo 3)
(symbol-value 'foo) => 3

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: stevenlien
Subject: Re: How to create a global variable without using setq or set??
Date: 
Message-ID: <McPj9.27034$q41.12340@news02.bloor.is.net.cable.rogers.com>
Thank you very much Barry, i got your point....

"Barry Margolin" <······@genuity.net>
> DEFVAR is the usual way.
>
> >I can't use setq because my prof told me that setq must place at the
global
> >level.
>
> This is not correct.  SETQ can and is used at all levels of programs.
E.g.
>
> (defun do-stuff (a b)
>   (let ((sum (+ a b)))
>     (setq sum (* sum sum))
>     sum))
>
> >I can't put setq under any function.......but i just can't think of any
> >other
> >function can do that....
> >
> >ie (defun afunction (name value)  (setq name value)) is not valid......
>
> This just sets the local variable NAME.  Functions are called by value, so
> they can't change the values of the variables that are used in the caller.
> If you need something that can work like that, you should write a macro,
> but I suspect you haven't gotten to that point in the class yet.
>
> You can use SET or SETF of SYMBOL-VALUE, but this requires that you pass
> a symbol to AFUNCTION.
>
> (defun afunction (name value)
>   (setf (symbol-value name) value))
>
> (afunction 'foo 3)
> (symbol-value 'foo) => 3
>
> --
> Barry Margolin, ······@genuity.net
> Genuity, Woburn, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the
group.