Re: New Python Syntax -- Guido's Reply

Kenneth Manheimer (
Fri, 27 May 1994 20:22:19 GMT

> 5) cutting and pasting code blocks.
> With a good editor, this should not be a problem, but not
> everyone has a good editor available. Some tools ( text widgets
> and Mac TEXTEDIT, have built in editing operations that don't
> respect white space. A related problem is how to cut and past
> from a interactive window and get rid of the ">>>" + '...'
> leading chars! )

For the first part of the problem, how about having some meta syntax
to express explicit adjustment of the current indentation column?
I imagine it wouldn't be disruptive of the grammar, and i think it
would be fairly legible.

Ie, a line occupied only by a '^' carat, with the carat pointing to
the new column location to be considered the current-nesting
indentation. Then code fragments could be inserted unchanged, with
the indentation temporarily adjusted to accomodate them - rehomed.
Subsequent rehoming could be used to restore the original indentation
margin, and simple utilities could readjust indentation to strip
rehoming, for any rehomed code you wish to keep.

Eg, here's some artificial use of rehoming to illustrate, with some
gratuitous butchering of existing Python demo code. (Neat stuff, this
code, overloading the interpretation of sequentiality like that!)


# Demo/ with some arbitrary rehoming for illustration purposes.

from string import joinfields
class Rev:
def __init__( self, seq ):
self.forw = seq
^ # Move indentation home back a tab.
self.back, unnecessary, yet, more = self, yet, more, unnecessary
^ # Restore discarded tab.
def __len__( self ):
return len( self.forw )
def __getitem__( self, j ):
return self.forw[ -( j + 1 ) ]
^ # Allow ostensibly-pasted def at left margin:
def __repr__( self ):
seq = self.forw
if type(seq) == type( [] ) :
wrap = '[]'
sep = ', '
elif type(seq) == type( () ) :
wrap = '()'
sep = ', '
elif type(seq) == type( '' ) :
wrap = ''
sep = ''
wrap = '<>'
sep = ', '
outstrs = []
for item in self.back :
outstrs.append( str( item ) )
return wrap[:1] + joinfields( outstrs, sep ) + wrap[-1:]

#Probably don't need to rehome for the class to close, since this is
#the end of the file.