[Fwd: Re: Something to ponder]
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 ---BeginMessage--- 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---
Re: [Fwd: Re: Something to ponder]
Aaron Sherman wrote: 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 [snip] $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; }); Could this just work with the switch statement somehow? If not, could 'when' be extended to take a signature that is matched against the return 'arguments'? given $sock.peername() { when(Net::Address::IP){ die Remote host unresolvable: '$_' } when(Net::Address){ die Non IP unresolvable address: '$_' } when(Str){ print Seemingly valid hostname: '$_'\n } } or more complexly sub foo { return time if time % 2; return (time, () = gmtime)# ya, I know p6 has a better way, # but I can't remember it right now } given foo(){ when(Int){ say $_, , join , gmtime $_ } when(Int $t, Array @gmt){ say $t, , join , @gmt } } Dan
Re: [Fwd: Re: Something to ponder]
I think this is something the optimizer could use to eliminate an ordinary return that happens to be followed by a call to a known set of something elses. So it might well help things like switch statements and cascaded function calls and tail recursion (and maybe invocation of autoloaded functions, a la goto foo). But I doubt we should go out of our way to introduce special syntax for it. Larry
Re: Precedence table update
On Sat, Aug 14, 2004 at 08:57:21AM -0700, Larry Wall wrote: : You'll also want to make sure the zip operator (¥) gets in there, : probably with the same precedence as == (unless we decide it's : a scalar-only operator, in which case it can be tighter because it : would only work on array refs). It also has self-associativity issues : much like ^ and == and, if you squint, semicolon inside subscripts. It the moment the zipper has moved to be the same precedence as comma, because it really wants to be looser than ranges but tighter than listops. Plus it's sort of like a »,« if you squint. I'm eagerly awaiting my first opportunity to use the »¥« operator in anger... Larry
Re: Precedence table update
Larry Wall skribis 2004-08-18 15:37 (-0700): It the moment the zipper has moved to be the same precedence as comma, because it really wants to be looser than ranges but tighter than listops. Plus it's sort of like a »,« if you squint. I'm eagerly awaiting my first opportunity to use the »¥« operator in anger... Which makes me wonder: is there another core-only set of operators that renders as ???, or can we safely assume that ??? is Y (I still don't see why infix:Y would be wrong, and want it badly, because prefix zip() doesn't quite feel the same)? Let's see... ?foo bar baz?# qw %foo?bar?# qw @foo ?+? @bar# hyper @foo ? @bar # zip I guess it's not as bad as I initially thought. Even when rendered badly, I think in most cases it will still be recognisable. (Hm, can the real ? be made intelligent enough to dwim? Then I can even *copy and paste* the new operators in this terminal and have it dwym.) Juerd
Re: Synopsis 2 draft 1
On Sat, 14 Aug 2004, Larry Wall wrote: To get a Perlish representation of any data value, use the C.repr method. This will put quotes around strings, square brackets around list values, curlies around hash values, etc., such that standard Perl could reparse the result. XXX .repr is what Python calls it, I think. Is there a better name? Is .dump taken? It reminds me of Data::Dumper.
Re: Synopsis 2 draft 1
On Wed, Aug 18, 2004 at 10:02:57PM -0600, John Williams wrote: : On Sat, 14 Aug 2004, Larry Wall wrote: : To get a Perlish representation of any data value, use the C.repr : method. This will put quotes around strings, square brackets around : list values, curlies around hash values, etc., such that standard : Perl could reparse the result. XXX .repr is what Python calls it, I think. : Is there a better name? : : Is .dump taken? It reminds me of Data::Dumper. Actually, I've settled on .perl for now, on the assumption there could also be a .python, a .ruby, a .cobol, a .intercal, etc. Larry
Re: Synopsis 2 draft 1
On 8/14/04, [EMAIL PROTECTED] (Larry Wall) wrote: To get a Perlish representation of any data value, use the C.repr method. This will put quotes around strings, square brackets around list values, curlies around hash values, etc., such that standard Perl could reparse the result. XXX .repr is what Python calls it, I think. Is there a better name? Hm, sounds like kind of a reverse-eval. .lave, when you want a nice, clean representation of your values! - David hey, I could've suggested .deval Green