Re: "no variable or argument declarations are necessary."
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: "no variable or argument declarations are necessary."

From: Paul Rubin <//phr.cx@NOSPAM.invalid>
Date: Fri Oct 07 2005 - 16:21:33 CEST

Mike Meyer <mwm@mired.org> writes:
> > When you want local variable in lisp you do :
> >
> > (let ((a 3)) (+ a 1))
>
> Excep that's not a decleration, that's a binding. That's identical to
> the Python fragment:
>
> a = 3
> return a + 1
>
> except for the creation of the new scope. Not a variable decleration
> in site.

Really not though, the scope is what makes it a declaration. In
Python you can say:

   for i in 1,2:
     if i == 2: print x # x is unbound the first time through the loop
     x = 9 # but bound the second time

and the print doesn't raise an error. Further, 'x' is still in scope
even after the loop exits. Scheme lets you say something like

  (define (counter)
    (let ((k 0))
      (define (f)
         (set! k (+ 1 k))
         k)
      f))

Yeah, I know you'd write it a bit more concisely in Scheme, but I
wanted to make it look like the Python equivalent:

  def counter():
     k = 0
     def f():
        k += 1
        return k
     return f

The trouble is, in f, k is neither local nor global, so Python throws
up its hands and raises an error. There's no way to tell it where to
find k. This could be solved with a declaration, if Python understood it.
Received on Sat Oct 15 04:16:12 2005