On 4/13/06, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > Steven Bethard wrote: > > I know 2.5's not out yet, but since I now have a PEP number, I'm going > > to go ahead and post this for discussion. Currently, the target > > version is Python 2.6. You can also see the PEP at: > > http://www.python.org/dev/peps/pep-0359/ > > > > Thanks in advance for the feedback! > [snip] > > Would it be possible/useful to have a pre-block hook to the callable, > which would provide the dictionary; this dictionary might not be > a proper dictionary (but only some mapping), or it might be pre-initialized.
Yeah, something along these lines came up in dicussing using the make statement for XML generation. You might want to write something like: make Element html: make Element head: ... make Element body: ... however, this doesn't work with the current semantics because: (1) dict's are unordered (2) dict's can't have the same name (key) twice and so you can only generate XML/HTML where the order of elements doesn't matter and you never have repeated elements. That's not really XML/HTML anymore. You could probably solve this if you could supply a different type of dict-like object for the block to be executed in. Then we'd have to have a translation from something like:: make <callable> <name> <tuple> in <mapping>: <block> to something like:: <name> = <callable>("<name>", <tuple>, <namespace>) where <namespace> is created by executing the statements of <block> in the <mapping> object. Skipping the syntax discussion for the moment, I guess I have two problems with this: (1) It complicates the statement semantics pretty substantially (2) It breaks the parallel with the class statement since you can't supply an alternate mapping type for class bodies to be executed in (3) It adds some degree of coupling between the mapping type and the callable. For the example above, I expect I'd have to do something like:: make Element html in ElementDict(): make Element head in ElementDict(): ... make Element body in ElementDict(): ... where I'd expect that ElementDict was really only useful if you were making Elements. It also seems a little inelegant to have to create a new ElementDict each time. To avoid this latter problem, I guess we could allow Element to supply a __getmapping__ hook which would be called to get the mapping to execute the block in, but then simple functions would not have access to the full functionality of the make statement. I guess I'm willing to consider the idea, but only if someone else presents a concrete proposal for the additional semantics (that's better than the one above) and a few use-cases showing how it would improve some code. STeVe -- Grammar am for people who can't think for myself. --- Bucky Katt, Get Fuzzy _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com