From: ··········@bbs.ee.ncu.edu.tw
Subject: Global variable is not so global
Date: 
Message-ID: <1130597276.904051.215320@g44g2000cwa.googlegroups.com>
For ivestigations of the "global behaviors" of the so called "global
variable" , I tried the follwoing codes in ARC xlisp-stat.

> (defvar *t* 100)
*T*
> (let ((*t* 10)))
NIL
> *t*
100
>

You have already seen that the global variable *t* didn't change value
after the binding by the let form.

So , global ? I'm afraid not so gloabal !

From: Kaz Kylheku
Subject: Re: Global variable is not so global
Date: 
Message-ID: <1130601737.090010.107030@g43g2000cwa.googlegroups.com>
··········@bbs.ee.ncu.edu.tw wrote:
> For ivestigations of the "global behaviors" of the so called "global
> variable" , I tried the follwoing codes in ARC xlisp-stat.

You know, Lisp isn't something that landed on earth from outer space.
It's a thoroughly documented human invention which you can get to know
properly by reading the the Common Lisp HyperSpec and other excellent
materials.

>
> > (defvar *t* 100)
> *T*
> > (let ((*t* 10)))
> NIL
> > *t*
> 100
> >
>
> You have already seen that the global variable *t* didn't change value
> after the binding by the let form.
>
> So , global ? I'm afraid not so gloabal !

That's okay. Other languages also suffer from this limitation:

   #include <stdio.h>

   int x = 100;

   int main(void)
   {
      {
         int x = 10;
      }

      printf("x = %d\n", x);
      return 0;
   }

The output is   100   .

So you see, Lisp isn't alone! C and C++ do not have global variables
either.

This is good because the use of global variables is bad design anyway.

In the old days, programmers only had global variables. There were no
funtions, only subroutines. To call another module, you would store
variables into some globals, then call a subroutine in that module. The
module would retrieve the values from those globals. If you wanted
recursion, you used arrays to simulate a stack.

Aren't you glad that recently introduced languages like C have banished
globals?

Phew...
From: ··········@bbs.ee.ncu.edu.tw
Subject: Re: Global variable is not so global
Date: 
Message-ID: <1130605502.562136.126800@g43g2000cwa.googlegroups.com>
I am not good at C-progamming. In fact my best skills are at prolog ,
or Turbo prolog for further specification .

I wrote this topic not for laughing at the fact that lisp doesn't have
real global variables, but for reporting the behavior of the so-called
global variables. I am new to lisp and I believe there are also many
people new to lisp. If we know the so-called global is in fact
misleading , our way to lisp will be more straightened.
From: Pascal Costanza
Subject: Re: Global variable is not so global
Date: 
Message-ID: <3shr6mFo9rk3U1@individual.net>
··········@bbs.ee.ncu.edu.tw wrote:
> I am not good at C-progamming. In fact my best skills are at prolog ,
> or Turbo prolog for further specification .
> 
> I wrote this topic not for laughing at the fact that lisp doesn't have
> real global variables, but for reporting the behavior of the so-called
> global variables. I am new to lisp and I believe there are also many
> people new to lisp. If we know the so-called global is in fact
> misleading , our way to lisp will be more straightened.

A public discussion forum like c.l.l is good for asking question, not 
for presenting answers to questions that noone asked. What you have 
stated about global variables in your posting is trivial knowledge that 
every run-of-the-mill Common Lisp tutorial explains much better.

If something is not clear to you, it is a good idea to formulate it as a 
question, and then the chances are very high that you will get helpful 
and constructive responses here.


Pascal

-- 
My website: http://p-cos.net
Closer to MOP & ContextL:
http://common-lisp.net/project/closer/
From: Pascal Bourguignon
Subject: Re: Global variable is not so global
Date: 
Message-ID: <878xwctedm.fsf@thalassa.informatimago.com>
"Kaz Kylheku" <········@gmail.com> writes:

> ··········@bbs.ee.ncu.edu.tw wrote:
>> For ivestigations of the "global behaviors" of the so called "global
>> variable" , I tried the follwoing codes in ARC xlisp-stat.
>
> You know, Lisp isn't something that landed on earth from outer space.

I'm not so sure.  http://www.lisperati.com/logo.html

> It's a thoroughly documented human invention which you can get to know
> properly by reading the the Common Lisp HyperSpec and other excellent
> materials.

But as the transistor and teflon, it comes directly from Roswell's ET
spaceships.


>> > (defvar *t* 100)
>> *T*
>> > (let ((*t* 10)))
>> NIL
>> > *t*
>> 100
>> >
>>
>> You have already seen that the global variable *t* didn't change value
>> after the binding by the let form.
>>
>> So , global ? I'm afraid not so gloabal !
>
> That's okay. Other languages also suffer from this limitation:
>
>    #include <stdio.h>
>
>    int x = 100;
>
>    int main(void)
>    {
>       {
>          int x = 10;
>       }
>
>       printf("x = %d\n", x);
>       return 0;
>    }
>
> The output is   100   .
>
> So you see, Lisp isn't alone! C and C++ do not have global variables
> either.
>
> This is good because the use of global variables is bad design anyway.
>
> In the old days, programmers only had global variables. There were no
> funtions, only subroutines. To call another module, you would store
> variables into some globals, then call a subroutine in that module. The
> module would retrieve the values from those globals. If you wanted
> recursion, you used arrays to simulate a stack.
>
> Aren't you glad that recently introduced languages like C have banished
> globals?
>
> Phew...


-- 
"Specifications are for the weak and timid!"
From: Mario Tanev
Subject: Re: Global variable is not so global
Date: 
Message-ID: <1nO8f.6827$BZ5.6314@newssvr13.news.prodigy.com>
Is this a joke?

Let creates a new lexical scope and you're printing *t* outside that scope.
If you wish to change the global binding, use setf instead of let.

··········@bbs.ee.ncu.edu.tw wrote:

> For ivestigations of the "global behaviors" of the so called "global
> variable" , I tried the follwoing codes in ARC xlisp-stat.
> 
>> (defvar *t* 100)
> *T*
>> (let ((*t* 10)))
> NIL
>> *t*
> 100
>>
> 
> You have already seen that the global variable *t* didn't change value
> after the binding by the let form.
> 
> So , global ? I'm afraid not so gloabal !
From: ··········@bbs.ee.ncu.edu.tw
Subject: Re: Global variable is not so global
Date: 
Message-ID: <1130608749.918055.224690@f14g2000cwb.googlegroups.com>
>Is this a joke?
>
>Let creates a new lexical scope and you're printing *t* outside that scope.
>If you wish to change the global binding, use setf instead of let

How about these codes?
> (defvar *t* 100)
*T*
> (let ((*t* 10))
      (setf *t* 1000))
 1000
> *t*
100
>

You can see that using setf to change the so-called "global variable "
is no more than a joke at all !
From: Peter Seibel
Subject: Re: Global variable is not so global
Date: 
Message-ID: <m2hdb0ry7i.fsf@gigamonkeys.com>
··········@bbs.ee.ncu.edu.tw writes:

>>Is this a joke?
>>
>>Let creates a new lexical scope and you're printing *t* outside that scope.
>>If you wish to change the global binding, use setf instead of let
>
> How about these codes?
>> (defvar *t* 100)
> *T*
>> (let ((*t* 10))
>       (setf *t* 1000))
>  1000
>> *t*
> 100
>>
>
> You can see that using setf to change the so-called "global variable "
> is no more than a joke at all !

Hmmm. Maybe you should try a different experiment:

  CL-USER> (defvar *t* 100)
  *T*
  CL-USER> (setf *t* 1000)
  1000
  CL-USER> *t*
  1000

You're still misunderstanding what LET is for which is causing you to
be confused about variables, global and otherwise.

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Peter Seibel
Subject: Re: Global variable is not so global
Date: 
Message-ID: <m2ll0crym3.fsf@gigamonkeys.com>
··········@bbs.ee.ncu.edu.tw writes:

> For ivestigations of the "global behaviors" of the so called "global
> variable" , I tried the follwoing codes in ARC xlisp-stat.
>
>> (defvar *t* 100)
> *T*
>> (let ((*t* 10)))
> NIL
>> *t*
> 100
>>
>
> You have already seen that the global variable *t* didn't change value
> after the binding by the let form.

Here's a hint: the whole point of LET is that it's effect is
temporary. All you've demonstrated is that LET is a binding rather
than assignment operator. A trip to the Hyperspec (or--shameless
plug--to the book listed in my .sig) may help clear up some of these
issues for you.

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: ··········@bbs.ee.ncu.edu.tw
Subject: Re: Global variable is not so global
Date: 
Message-ID: <1130609374.216940.281010@f14g2000cwb.googlegroups.com>
Peter , thanks for your comments , and thanks for your book .

I totally agree with you .

By the way , the codes in your book recently help me identifying bug in
GCL-2.6.6 . Your book is really useful.

I think those new to lisp also appreciate your book !
From: Giorgos Keramidas
Subject: Re: Global variable is not so global
Date: 
Message-ID: <86psoj1z1i.fsf@flame.pc>
··········@bbs.ee.ncu.edu.tw writes:
> Peter , thanks for your comments , and thanks for your book .
> [...]
> I think those new to lisp also appreciate your book !

We do :)

I've read the online copy of the book, but still went ahead and
bought myself a hardcopy version from a bookstore.  The trip from
San Francisco back to Europe was *really* fun, is the least I can
tell about it.
From: Rainer Joswig
Subject: Re: Global variable is not so global
Date: 
Message-ID: <joswig-E2D84E.20094729102005@news-europe.giganews.com>
In article <························@g44g2000cwa.googlegroups.com>,
 ··········@bbs.ee.ncu.edu.tw wrote:

> For ivestigations of the "global behaviors" of the so called "global
> variable" , I tried the follwoing codes in ARC xlisp-stat.
> 
> > (defvar *t* 100)
> *T*
> > (let ((*t* 10)))
> NIL
> > *t*
> 100
> >
> 
> You have already seen that the global variable *t* didn't change value
> after the binding by the let form.
> 
> So , global ? I'm afraid not so gloabal !

Why not read a good book about Lisp instead?
Things might be clear after reading it...

Here os a good one:

Common Lisp: A Gentle Introduction to Symbolic Computation

http://www.cs.cmu.edu/~dst/LispBook/

Available in Postscript and PDF. Also with software.
From: John Thingstad
Subject: Re: Global variable is not so global
Date: 
Message-ID: <op.szfblo0bpqzri1@mjolner.upc.no>
On Sat, 29 Oct 2005 16:47:56 +0200, <··········@bbs.ee.ncu.edu.tw> wrote:

> For ivestigations of the "global behaviors" of the so called "global
> variable" , I tried the follwoing codes in ARC xlisp-stat.
>
>> (defvar *t* 100)
> *T*
>> (let ((*t* 10)))
> NIL
>> *t*
> 100
>>
>
> You have already seen that the global variable *t* didn't change value
> after the binding by the let form.
>
> So , global ? I'm afraid not so gloabal !
>

Search google for lexical scope.
Though how you have managed to avoid learning about it is well.. odd
I think you are pretty alone in finding this behaviour wrong..


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/