MLUG: Re: [MLUG] guess what
Re: [MLUG] guess what
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
On Thu, Apr 01, 2004 at 02:20:54PM -0600, Jonathan King wrote:
> 
> On Thu, 1 Apr 2004, Mark Rages wrote:
> 
> > On Thu, Apr 01, 2004 at 07:42:13PM +0000, EMAIL:PROTECTED 
> > > wrote:
> > >
> > > Oh, and did they ever fix the following?
> > >
> > > i=1
> > > def f():
> > >   print "i=",i
> > >   i = i + 1
> > >
> > > f()
> > >
> > > Hint: It does not print "i=2".
> > 
> > I don't get it.  Why would you expect it to?  If you don't understand
> > Python's scoping rules you might expect "i= 1" but whence 2?
> 
> I noticed that typo as well.  But nobody has every made it clear to 
> me why Python does not have true lexical scoping.  My best guess was 
> that, lacking a non-white-space bracketing device, you just can't do
> this:
> 
> {
>     $i = 1;
> 
>     sub counter {
> 	$i++;
>     }
> }
> 
> Or actually, why that wouldn't be done in Python as
> 
> i=1
>     def counter()
>         i = i+1
> 
> # more stuff
> 
> > Of course you need to define i as global to see outside the
> > function scope.
> 
> Except that *makes* i global.  In a true closure, i is *local*.  And 
> you're not seeing outside the function scope, you're seeing your 
> own lexical scope.  
>  

In Python, you would do this:

i=1
def f():
   global i
   print "i=",i
   i = i + 1

Is this what you thought I meant?

Can you explain what you mean by a "true closure"? Assume you're talking 
to a known idiot.  (I have no computer science training beyond one 
miserable CECS203 class.  And Fortran of course.)

> Block structuring delimeters {} are (wait for it...) what give you
> blocks.  Blocks are good.

Python has blocks; they're just denoted by whitespace.  Like English.
 
> Statement delimiters are (wait for it again...) what give you
> statements.  Python would be just as good (actually, much BETTER if
> it made these things explicit.  It's been awhile, but when I found
> that you often had to use line continuation devices in Python, I
> thought "How quaint."  It turns out that Python (at least then) 
> wasn't expression oriented but *statement* oriented.  I guess you 
> could say "to each his own" but there were reasons why he hashed 
> this stuff out in the 70s and decided that expressions and blocks 
> were Good Things.  This is NOT leading edge kind of stuff.

If you break the lines in places like after a , or + then you don't need 
explicit line continuation.  (You can use ; to separate expressions if 
you so desire)

> (Snip rest; I never used PHP once I saw it's dorkiness.)

Would that I had followed your example.

Regards,
Mark
EMAIL:PROTECTED
-- 
To invent, you need a good imagination and a pile of junk. -Thomas Edison
_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members