durusmail: quixote-users: Thoughts on a block-syntax extension to PTL
Thoughts on a block-syntax extension to PTL
2005-08-22
2005-08-22
2005-08-22
2005-08-22
2005-08-22
2005-08-23
2005-09-07
Thoughts on a block-syntax extension to PTL
Graham Fawcett
2005-08-23
Jason Sibre wrote:

 >I like this.  I'm still not sure I'd use it ;) (see my previous
 >thoughts on the toy nevow implementation), but I like the syntax.
 >I'm not going to pretend to know what you're doing to get that to
 >work, but if it works as advertised, I'd give it a try.

Thanks, Jason. I re-read your "toy nevow" comments[1]. Right now, the
"useless syntax errors" issue definitely still applies. ;-) As for the
"multitude of languages" problem, I personally think that my proposal
is a step in the right direction. PTL is just sugar on a Python
script; my proposal just adds a bit more sugar; but it's still Python,
not another language.

 >I'm also under the impression that this (unlike the toy nevow thing)
 >would be rewritten at import time, so the performance hit would be no
 >worse than PTL... Am I right?

Yes, the rewrite is at compile time. I couldn't promise there would be
no performance hit at all, and my current impl. is certainly not
optimal, but I'm certain it could be optimized. (I would sacrifice
some flexibility in favour of performance in a serious
implementation.)

The current implementation does something like this. When it finds a
block statement like:

    P(id='25'):
        'It is a fine day.'

It translates the statement, before passing it to the PTL compiler,
into:

    tmpXXXX = P(id='25')
    tmpXXXX.open_block()
    if True:
        'It is a fine day.'
    tmpXXXX.close_block()

Lots of room for improvement. ;-) But it does work.

I am fighting somewhat with htmltext, though, and am mulling over some
of Mike's comments. I wish that my Tag objects could either subclass
htmltext (with extra __slots__ for my own data) or could support an
"__htmltext__" method that PTL would take advantage of. "Standalone
tags" like the "TD:" lines in my earlier example are being rendered as
escaped strings, which is not what I want, of course. I may need to
rethink my implementation somewhat.

Anyway, if you're playing with the example, you may need to strip out
any htmltext references in eptl_tags.py, and use it only in [plain]
functions, until I can get the bugs out. Comments and thoughts on this
are welcome!

Having said that, I still like the thing. If I can get it to perform
well, I would prefer it to plain PTL.

Thanks,
Graham

[1]
http://mail.mems-exchange.org/pipermail/quixote-users/2004-January/002457.html

reply