new symbol request/idea

Carey Evans careye at spamcop.net
Sat Apr 14 20:19:07 EDT 2001


"Pete Shinners" <shredwheat at mediaone.net> writes:

> i've occasionally thought it would be a good idea for there
> to be a special symbol, when found at the start of a line
> means "this line has the same indentation as the previous"

[...]

>     glBegin(GL_LINES)
>     @   glColor(r,g,b)
>         glVertex(x,y,z)
>         glVertex(x,y,0)
>     glEnd()
> 
> #or
> 
>     deep_involved_code()
>     something_not_quite_right()
> @print 'SOME DEBUG INFO', x()
>     back_to_work()

This isn't consistent.  In the first case, indentation on following
lines is the same as the first line with the "@", and the "@" itself
has the same indentation as the preceding line.  In the second, the
indent before the "@" changes, and the following line has the same
indent as the preceding line.

I suppose in the first case, the tokenizer could be modified to
increase the indentation level to the same as any whitespace following
the "@", and ignore the corresponding DEDENT.  Supporting just the
second case would be possible too, if *every* improperly indented line
started with "@".

Supporting both would require very careful specification of what was
supposed to happen, and the code to parse it would be terrifying.

[...]

>     prepare_code()
> #    if special_case():
> @        this_is_how_we_do_it()
>         print 'Handled'
>     code_as_normal()

Assuming that you meant the print to have the same indentation as the
call to this_is_how_we_do_it(), this could be done just as easily by
writing something like:

    prepare_code()
    #if special_case():
    if 1: # DEBUG
        this_is_how_we_do_it()
        print 'Handled'
    code_as_normal()

You could also write one of the following, depending on circumstances
and which you like best:

    if 1 or special_case():

    if 1: # if special_case()

> anyways, the syntax is slightly unclean enough it wouldn't be
> used liberally, but there's simply times i want python to just
> ignore the indentation for a couple lines, and there is no way
> to do it.

The only case I can really see justified is your very first one, and
there's no question in my mind that it would get abused for much less
readable code.  What *I* would like to be able to do in this case is
use some sort of macro system and write this:

    gl GL_LINES:
        glColor(r,g,b)
        glVertex(x,y,z)
        glVertex(x,y,0)

like I could do in Tcl or Lisp, but I don't see that happening either.

-- 
	 Carey Evans  http://home.clear.net.nz/pages/c.evans/

	    "Quiet, you'll miss the humorous conclusion."



More information about the Python-list mailing list