This bit comes from the p6i list, and I just thought I'd ask those
in-the-know if my suggested "returntype" role/property would make sense
here, or if there's another way to do it that makes more sense?
For that matter, does MMD on return type map into Perl6's gestalt at
all, or would it be tumorous?
To sum up:
Dan: return continuations and MMD calling means we can dispatch return
via MMD
Aaron: suggested an implementation in Perl and Python. In Perl, it would
be a role/propery called "returntype" that would take some sort of list
or hash of types and closures. The difference between this and a
given/when block being that the MMD internals of parrot handle which
closure is invoked based on the return type. Thus, very low overhead.
My example in the attached message is mostly error handling, but that's
obviously not the only way it could be used....
--
â 781-324-3772
â [EMAIL PROTECTED]
â http://www.ajs.com/~ajs
--- Begin Message ---
On Tue, 2004-08-17 at 16:22, Felix Gallo wrote:
> On Tue, Aug 17, 2004 at 04:08:34PM -0400, Dan Sugalski wrote:
> > 1) We're going to have MMD for functions soon
> > 2) Function invocation and return continuation invocation's
> > essentially identical
> > 3) Therefore returning from a sub/method can do MMD return based on
> > the return values
> $x -----\
> \
> @mylist -+--- $obj.mymmdsub;
> /
> %hash --/
How very fungible of you ;-)
Still, I think that's a nice APPLICATION, but the concept is more
flexible, if I understand it correctly. It would be something that would
look more like a cross between exception handling and a switch
statement.
I would think it would look more like (again, Perlish example):
$sock.peername()
does returntype(
Net::Address::IP -> $ip {
die "Remote host unresolvable: '$ip'";
}, Net::Address -> $addr {
die "Non IP unresolvable address: '$addr'";
}, Str -> $_ {
print "Seemingly valid hostname: '$_'\n";
});
Of course, that's just Perl. Perhaps Python would add something that
would look like:
returnswitch: sock.peername()
returncase os.net.addr.ip:
lambda ip: raise OSError, "Unresolvable %s" % str(ip)
returncase os.net.addr:
lambda addr: raise OSError, "Unresolvable non-IP %s" % str(ip)
returncase str:
lambda name: print "Seemingly valid hostname: '%s'" % name
My python skills are still developing, so pardon me if I've gotten it
wrong, and I'm just inventing os.net.addr.ip for purposes of
pseudo-code....
Is that the kind of thing you had in mind, Dan, or am I misunderstanding
how return continuations work?
--
â 781-324-3772
â [EMAIL PROTECTED]
â http://www.ajs.com/~ajs
--- End Message ---