"robert" <[EMAIL PROTECTED]> wrote:
> Hendrik van Rooyen wrote: > > So far I have only used dicts to pass functions around > > in a relatively unimaginative static jump table like way... > > > Probably one has just to see that one can a pass a function object > (or any callable) around as any other object. > Similar to a function address in assembler/C but very comfortable > and with the comfort of closures (which automatically hold the > status of local variables): > > def f(): > print "hello" > > def g(func): > print "I'll do it ..." > func() > print "done." > > > def run(x): > g(f) > a="local variable\n" > def h(): > b="inner local" > print "inner function" > print x,a,b > g(h) > g(lambda:sys.stdout.write(a)) > > run(1) > > From there its just natural to not pass dead objects through an > inter-thread queue, but just code as it or even a "piece of > critical code" ... > A small step in thought, but a big step in effect - soon > eliminating bunches of worries about queues, pop-races/None > objects, protocol, serialization, critical sections, thousands of > locks etc. Thanks - this simplicity takes a bit of getting used to - I am used to passing what are effective entry point pointers around while building state machines that run under interrupt - effectively dynamically changing vectors for ticker based routines. But on the low level, trying to pass data at the same time is a bit of a pain, as you have to look after it yourself, so the temptation is great to only use globals... This passing_the_function_along_with_its_data is neat... *sigh* now if only it were possible to do it over a serial link, in the same way as through a queue (I know about Pyro, but this does not seem quite the same thing ) I suppose its not really possible - because while I suspect only "pointers" get passed through say a queue, you would have to send the actual code along as well over a link - or you need a mirror of the code on both sides, and a way to translate addresses - which I suppose is why Pyro looks like it does. I am working on something similar on a *very* small scale at the moment, in the context of control of physical things. Hence the sigh. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list