UserLinux chooses Python as "interpretive language" of choice
Paul Moore
pf_moore at yahoo.co.uk
Sat Dec 20 12:42:19 EST 2003
Oren Tirosh <oren-py-l at hishome.net> writes:
> I've always considered the visitor pattern as a rather poor substitute
> for generators, not as a something worth having for its own sake. Using
> generators instead of visitors+anonymous functions obviously reduces the
> need for anonymous functions (not that it's any excuse for not having
> something better than Python's lambdas!).
This is a bit out of context, as I've not read the full thread here,
but while I can see that the visitor pattern doesn't offer anything
much over generators for a *single* visitor function, I'm not sure how
that generalises to visitors with multiple "visit" methods.
Consider a file-tree walker, which takes a visitor. On each directory
seen, the visit_directory() method is called, on each file seen, the
visit_file() method is called, and on each symlink seen, the
visit_symlink() method is called.
Replacing that with generators seems like it may be clumsy. Or have I
missed a simple transformation?
Paul.
--
This signature intentionally left blank
More information about the Python-list
mailing list