[Zope] Zope and Polymorphism

Tres Seaver tseaver@palladion.com
Fri, 11 Feb 2000 22:52:21 -0600


Evan Simpson wrote:
> 
> ----- Original Message -----
> From: Tres Seaver <tseaver@palladion.com>
> > > > Or, as an alternative, we could extend the <dtml-in> tag to pass in a
> filter
> > > > expression as an additional argument::
> > > >
> > > >   <dtml-in name=objectValues filter="self.hasMetaType( 'Document' )">
> > > >
> > On further thought, this is better solved by repeating
> >
> >  <dtml-forever>
> >   <dtml-mantra> Separate content from presentation! </dtml-mantra>
> >  </dtml-forever>
> >
> > More seriously, PythonMethods are the Right Thing (TM) here.
> 
> I disagree ;-)  Not that PMs aren't good for this; they are, of course.  But
> I'd hate to have to write one for something this piddling when the extension
> really wouldn't be that bad:
> 
> <dtml-in objectValues filter="meta_type == 'DTML Document'">

Ah, I was not advocating removing the argument from object values -- I was
backtracking on the idea of adding a "filter=" attribute to the <dtml-in> tag. 
I changed my ground because, for anything more complicated than the simple
meta_type check, the design "smells better" if I factor the filtering out to a
PythonMethod (it gets much easier to reuse or parameterize the logic, for
instance).

> 
> If the condition was more complex, then I would lean towards encapsulating
> it in a PM, and writing:
> 
> <dtml-in objectValues filter=LeftHandedWuzzleWidgets>

Or just::

  <dtml-in LeftHandedWuzzleWidgets>

> 
> This allows you some orthogonality between your condition and the sequence
> you're applying it to.
> 
> > P.S.:  This would be even cooler, except PythonMethods don't have
> map/filter
> > available:
> 
> I'm still not sure why DTML leaves out filter and reduce.  'map' I can sort
> of understand, but not the other two.  Put them in DTML, and PMs get them
> automatically.

Blocking the "simple" uses of map (apply a function to each item in a list)
makes no sense:  that is logically no different than removing <dtml-in>! 
Funkier uses, like splicing parallel lists into lists of tuples, maybe.  I agree
that adding filter and reduce would be dead easy;  I don't use reduce much
myself, but filter would be really nice to have.

Adding a filter= keyword to the <dtml-in> tag doesn't quite do it -- applying an
arbitrary filter expression to the objects one normally iterates over seems
non-trivial, at least without munging in lambda, too (I can hear the screams
already!).  I guess one could require that the filter attribute name a callable
(as in your example above).

Best,

Tres.
-- 
=========================================================
Tres Seaver         tseaver@palladion.com    713-523-6582
Palladion Software  http://www.palladion.com