Re: Non-declared Variables

Pascal Bourguignon <pjb@informatimago.com>
28 Oct 2006 01:23:53 -0400

          From comp.compilers

Related articles
Non-declared Variables acampbellb@hotmail.com (Avatar) (2006-10-16)
Re: Non-declared Variables int2k@gmx.net (Wolfram Fenske) (2006-10-17)
Re: Non-declared Variables gnorik@gmail.com (2006-10-24)
RE: Non-declared Variables qtj-query@shaw.ca (Quinn Tyler Jackson) (2006-10-26)
Re: Non-declared Variables Peter_Flass@Yahoo.com (Peter Flass) (2006-10-26)
Re: Non-declared Variables pjb@informatimago.com (Pascal Bourguignon) (2006-10-28)
Re: Non-declared Variables ArarghMail610@Arargh.com (2006-10-28)
Re: Non-declared Variables genew@ocis.net (Gene Wirchenko) (2007-01-28)
| List of all articles for this month |

From: Pascal Bourguignon <pjb@informatimago.com>
Newsgroups: comp.compilers
Date: 28 Oct 2006 01:23:53 -0400
Organization: Informatimago
References: 06-10-098 06-10-108
Keywords: design
Posted-Date: 28 Oct 2006 01:23:50 EDT

Quinn Tyler Jackson <qtj-query@shaw.ca> writes:


>> I don't think that it is a good idea when language definition allows
>> you to use variables without declaration.
>
> I think languages should forbid the declaration of variables, for the
> following reasons:
> [...good reasons...]


But there's one thing where you need to declare the variables, it's
when you have lexical scope.


{
      x=0;
      {
            x=1;
            print x;
      }
      print x;
}


What does this print? Is there one or two variables? What about: {{
x=1; } print x;} and other such cases? Of course you can have only
dynamic variables and no lexical scope.


But I think the conclusion reached 20 years ago was that having only
dynamic scope without lexical scope was bad, and even that it'd be
better to have only lexical scoping...


That said, in lisp for example, we don't really declare the variables,
we directly bind them:


(let ((x 0))
      (let ((x 1))
            (print x))
      (print x))


and we get printed 0 and 1.






[Additionnal declarations can be inserted, but are optional.


  (let ((x 0))
        (declare (type integer x)
                          (special x))
        (let ((x 1.0))
              (declare (type float x))
              (print x))
        (print x))
]




--
__Pascal Bourguignon__ http://www.informatimago.com/


"Klingon function calls do not have "parameters" -- they have
"arguments" and they ALWAYS WIN THEM."



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.