durusmail: quixote-users: New syntax for PTL templates?
New syntax for PTL templates?
2002-10-08
2002-10-08
2002-10-08
2002-10-08
2002-10-09
2002-10-09
2002-10-09
2002-10-09
2002-10-10
PTL for SQL (was Re: [Quixote-users] New syntax for PTL templates?)
2002-10-10
python 2.2 required for widgets
2002-10-28
2002-10-28
2002-10-28
2002-10-28
quote keyword on widget constructors
2002-10-29
2002-10-29
2002-10-29
2002-10-28
2002-10-28
2002-10-29
2002-10-29
2002-10-29
2002-10-10
New syntax for PTL templates?
Greg Ward
2002-10-09
On 09 October 2002, dbinger said:
> I disagree with this notion.  Templates and functions are not
> distinguished
> by what types of things they return:  either may return anything.
> The distinction is only in what they do with statements whose
> values are string (-like), and in what they return by default.
> A template really *is* a function written in a convenient format.

Another way of stating this is that the difference between functions and
templates is *how you specify* the return value, not what the return
value can be.  (Although templates are more limited there, too, as long
as you don't use "return" in a template -- in which case why bother
making it a template?)

Coming back to the analogy with generators: from the caller's point of
view, a generator just returns a sequence -- ie. it's a callable that
is limited in what it can return, and it specifies its return value in a
funny way, by yielding one element at a time.

There's a case to be made that adding this to the language justifies
adding a new keyword to be used in place of "def".  But that side lost,
so "def" is used for both regular old functions and for generators.
Templates are just a third kind of callable that, like generators, have
a limited range of return values and a funny way of specifying the
return value.  So using "def" for templates is perfectly consistent with
existing precedent.

>  I also like it for being slightly more
> compact, and
> because emacs will colorize the def form without any special
> customization. ;)

If I hadn't spent an hour or so many many months ago hacking python.el
so it could handle PTL properly, I'd buy this argument.  But emacs
handles PTL just fine for me... ;->

        Greg
--
Greg Ward - software developer                gward@mems-exchange.org
MEMS Exchange                            http://www.mems-exchange.org


reply