[Zope] Use of lambda expression in DTML
Kevin Dangoor
kid@kendermedia.com
Tue, 30 May 2000 10:07:26 -0400
----- Original Message -----
From: "Lalo Martins" <lalo@hackandroll.org>
To: <zope@zope.org>
Sent: Monday, May 29, 2000 11:40 PM
Subject: Re: [Zope] Use of lambda expression in DTML
> On Mon, May 29, 2000 at 10:58:54PM -0400, Chris McDonough wrote:
> >
> > > <dtml-in "_.map (lambda item: Catalog.getobject
(item.data_record_id_),
> > > Catalog (REQUEST)">
> >
> >
> > How could someone understand this when you're finished with it?
>
> Perfectly clearly for anyone used to functional programming;
> I'd even say, clear on first sight. A lot easier to understand
> and maintain than a separate method.
Assuming I'm reading this correctly, I think I'd probably express this as:
<dtml-in "Catalog(REQUEST)">
<dtml-with "Catalog.getobject(data_record_id_)">
...foo...
</dtml-with>
</dtml-in>
BTW, I agree that exprs should be a part of DTML. You don't want to put
significant program logic in DTML, but there are many places in which exprs
are useful:
Total: <dtml-var "subtotal + shipping">
I'll grant that you can set up all of the variables you need via a
PythonMethod beforehand, but things like this can be nice and convenient...
Any power that can be given to PythonMethods securely is a boon.
Kevin