On 11/16/06, Antoine <[EMAIL PROTECTED]> wrote: > > Hi, > > > Well, if you find that easy to read and clear, I suspect you're more of > > a JavaScript programmer than a Python programmer. Here's how a more > > general form of the above would look in Python: > > > > response = (yield server.get_synset_links()) > > format_expanded(li.content, response.related) > > This assumes there is an underlying event loop of some sort that accepts > and is able to schedule generators. > Much more annoyingly, all your "yield"'s must be in the same scope, they > can't be spread in various subfunctions called from the generator. It is a > massive limitation to writing clean code, unless your generators are very > short. > > > def handle_response(record): > > format_expanded(li.content, response.related) > > server.get_synset_link(handle_response) > > As already mentioned, the problem with this idiom is that code that is > executed *after* appears *before* the "get_synset_link". > It makes the code less straightforward to write and especially to read > (and having readable code is important).
This is a bit biased by my dislike of event-driven programming, but: def x(): response = yield server.do_command('get_synset_links') format_expanded(li.content, response.related) event_loop.add(x()) It may be possible to clean it up further with decorators, anonymous functions, or "suites", but it's interesting to note that the bulk of the code contains no functions (anonymous or named) at all—one is only used to wrap it all in a new "thread". Another benefit is that any error handling can use traditional python methods: a try/except wrapped around the operation that may fail. TOOWTDI. And yes, it does still require an event loop, but so does your original javascript example; what do you think calls your callback? -- Adam Olsen, aka Rhamphoryncus _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com