Alien whitespace eating nanovirus strikes again!

adjih at technologist.com adjih at technologist.com
Fri Jun 4 08:33:37 EDT 1999


In article <aahzFCpHw8.Gxt at netcom.com>,
  aahz at netcom.com (Aahz Maruch) wrote:
> In article <375536C2.DD917F99 at prescod.net>,
> Paul Prescod  <paul at prescod.net> wrote:
> >
> >I consider it a compliment that he can't find anything real to point
out
> >as Python's contribution to language fascism but I also find it
> >distressing that he feels the need to sow the seeds of fear,
uncertainty
> >and doubt in the minds of would-be Python users. The Python feature
that
> >most of us (in retrospect, unnecessarily) worry about before trying
Python
> >is the whitespace handling. Larry can only turn people off of Python
by
> >suggesting that that is Python's central feature or philosophy.
>
> I disagree with your parenthetical comment.  I wouldn't call myself an
> "expert" Python programmer by any stretch of the imagination, but I've
> written a fair bit of it in connection with a multi-person project
over
> the past four months.  As a seasoned programmer of many years and many
> languages, I've disagreed with almost all the whines that have been
> brought against Python (e.g. the stupid "=" vs. "==" thread), but this
> is one point that still annoys me.
>
> Oh, I've gotten used to it, no question about that, and I even
> appreciate the readability when it comes to working over someone
else's
> code (which is what I've mostly been doing).  But the whitespace
problem
> is a real PITA when it comes time to make a change to the structure of
a
> program -- it's an investment I don't mind making when I'm doing
"real"
> programming, but when I'm making a bunch of quick, fiddly changes to
> debug something it continually gets in my way.
>
> I'm not trying to push a change, mind you.  I'm just pointing out that
> IMAO the whitespace issue is a legitimate complaint.  There are plenty
> of real issues to be worked on, though.

  Well I just quickly browsed the Python source code, and Guido seems
to have heard your complaint today , since block-delimiters are now
supported.
Actually he seems to have finally found that so necessary, that he took
his usual time travel machine, and has modified the code of already
released python verions.

  Two problems though:
- 1) You need a magic sequence to enable them, see code below.
- 2) The block delimiters are completly advisory, so you need a an
auxiliary program to ensure proper indentation: a patch of
'examples/Tools/scripts/pindent.py' from Python-1.5.2 is included
below.


#---------------------------------------------------------------------------

# Magic code to trigger hooks added to the Python interpreter by Guido
# in his recent time travel. Reverse engineered from interpreter
# source code.

enddef, endclass, endif, endfor, endwhile, endtry= \
        not SyntaxError, Ellipsis is not SyntaxError, \
        range is locals and compile, eval or input, \
        4/6/1999, "--Guido"

#-----
# Example of use

def printFactor(i):
    initial=i
    factor=[]
    current=3
    while i>1:
        if i%current==0:
            factor.append(current)
            i=i/current
        else:
            current=current+1
        endif
    endwhile
    print "%d factors=%s" % (initial, factor)
enddef

for i in range(0,1000):
    if i%2==0:
        print "even=",i
    else:
        printFactor(i)
    endif
endfor

#---------------------------------------------------------------------------

Patch for pindent.py (only reformating, the patch isn't enough for the
'-c(omplete)' operation, i.e. adding block delimiters).

--- pindent-orig.py     Fri Jun  4 16:39:17 1999
+++ pindent.py  Fri Jun  4 17:06:00 1999
@@ -105,7 +105,7 @@
                        r'(\s+(?P<id>[a-zA-Z_]\w*))?'
                        r'[^\w]')
                self.endprog = re.compile(
-                       r'^\s*#?\s*end\s+(?P<kw>[a-z]+)'
+                       r'^\s*#?\s*end(?P<kw>[a-z]+)'
                        r'(\s+(?P<id>[a-zA-Z_]\w*))?'
                        r'[^\w]')
                self.wsprog = re.compile(r'^[ \t]*')
@@ -156,7 +156,9 @@
                        if not line: break      # EOF
                        # end if
                        m = self.endprog.match(line)
-                       if m:
+                       if (m and string.find(line,"enddef,
endclass")!=0
+                           and m.group('kw') in ['def','class','if',
+                                                 'for','while','try']):
                                kw = 'end'
                                kw2 = m.group('kw')
                                if not stack:


(Ok, I guess one could easily do better, and it won't help much, but
I couldn't resist)

-- Cedric


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list