in reply to Re^2: IO::Lambda: call for participation
in thread IO::Lambda: call for participation
Likewise, after puzzling my way through the documentation, I'm intrigued, but see a steep learning curve before I'd understand how I'd use this in practice. I don't think this is unique to IO::Lambda -- POE has a similar, perhaps even steeper learning curve. It wasn't until I struggled through POE::Kernel and POE::Session and similar documentation that I really understood what was going on.
Some reactions:
In general, I think you assume too much knowledge of functional programming and use too much unfamilar jargon (e.g. "predicates") without clearly explaining each one. The whole "apologetics" section should be moved to the end as it distracts from explaining how to use the module.
The synopsis itself is too complex or else insufficiently commented to explain what is going on.
Many of your examples might be clearer if you were explicit about return and fixed up some indentation. E.g. edited from the synopsis:
# return an IO::Lambda object for a given $host sub http { my $host = shift; my $socket = IO::Socket::INET-> new( PeerAddr => $host, PeerPort => 80 ); return lambda { context $socket; # argument stack for other calls # register a callback for when $socket is writable write { print $socket "GET /index.html HTTP/1.0\r\n\r\n"; my $buf = ''; # register a callback for when $socket is readable read { return $buf unless sysread( $socket, $buf, 1024, length($buf)); # restart the "read" state if more is available again; } } } }
There are too many ways of doing things described too early and without context (no pun intended). For example:
A lambda is initially called with some arguments passed from the outside. These arguments can be stored using the call method; wait and tail also issue call internally, thus replacing any previous data stored by call. Inside the lambda these arguments are available as @_.
The part in bold is extraneous and distracting, as it forces the reader to ponder the relationship between different ways of calling a lambda -- it exposes implementation details that are irrelevant to initial understanding. Moreover, I think you mean that the arguments are made available as @_ in the callback attached to the lambda object. "Inside the lambda" is a bit vague.
Overall, I think you might need to explain more of the core principles for async programming and why they are necessary. Likewise, I think you need to explain subtleties in your examples, like why the "read" predicate is inside the "write" predicate. (Presumably, we don't want to start listening until we've actually sent the request via the write predicate.)
Then I think you need to walk through what happens in an example. So the "http" lambda is executed via "wait" -- a "write" state callback is registered. (Is it executed immediately? Does it execute after the lambda callback executes?) The "write" state is the only one registered and it's immediately valid (socket is writeable) so the "write" callback is executed. During that callback, a "read" state callback is registered. When the "write" callback finishes, the socket is readable so the "read" callback is executed one or more time. And so on. (Why does execution stop?)
So my general advice is to start very small, very simple and explicit and then build up from there.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: IO::Lambda: call for participation
by dk (Chaplain) on Jan 05, 2009 at 19:35 UTC | |
by merlyn (Sage) on Jan 05, 2009 at 19:58 UTC | |
by xdg (Monsignor) on Jan 05, 2009 at 21:03 UTC | |
by zby (Vicar) on Jan 05, 2009 at 22:29 UTC | |
by dk (Chaplain) on Jan 06, 2009 at 08:17 UTC | |
by zby (Vicar) on Jan 06, 2009 at 09:19 UTC | |
| |
by dk (Chaplain) on Jan 05, 2009 at 21:51 UTC |