On Mon, 28 Oct 2002, Austin Hastings wrote: : How about "leave"? Right, that brings back some memories.
: leave : <SURROUNDING> | [<SURROUNDING>]<IDENTIFIER> : [ [result] <VALUE-SPEC> ]; : : Aliases: : ========= : return -> "leave sub" Right. : exit -> "leave program" (or is it "thread"?) Hmm. Dunno. I'll assume thread for now. At least under some thread models, it's the main thread's exit that counts for the program exit. But I'm not a threading expert (yet). : break -> "leave loop" (this is shaky: does it deserve to be here?) That's "leave switch", or "leave topic", or some such, I'd think. : last -> "leave block" That's "leave loop", I expect. What I'm thinking of as "ret" is: ret leave block ret $x leave block, $x One could argue that leaving the innermost block should be the default, but that doesn't quite make "leave" a synonym for "ret". It's one of those situations where you want to have two different defaults in different situations. Hmm. Suppose instead of a function, we have a method, and scope matching happens via class just as with exceptions: return -> Sub.leave return $x -> Sub.leave($x) exit -> Thread.leave exit $x -> Thread.leave($x) break -> Topic.leave last -> Loop.leave last LABEL -> Loop.leave(label => "LABEL") ret -> Block.leave ret $x -> Block.leave($x) Then you could also have a global sub *leave that defaults to Block. Then "ret" is officially unnecessary, since you could say leave($x) Except that "leave" doesn't read right for that--sounds like you're wanting to "leave $x". Maybe it's leave(value => $x) but that's not very concise. Perhaps it doesn't matter, since the usual way to return a value from a block looks like this: { ... $x; } But if you're gonna define a global sub anyway to default the invocant, maybe *ret will be more meaningful to people than *leave. Or maybe it should be *val. Except that val($x) could be misread as setting the value without returning... : Extensions (these are WAY! optional): : ========================== : enter $jb BLOCK; : leave $jb [result $val]; I'd say those would map to $jb.enter {...} $jb.leave(value => $val); presuming we wanted to get that fancy, which most of us won't. But I do very much like the general "leave" idea. It's one of those simplifications we're looking for. The hallmark of such simplifications is whenever you can say "A is just a B". Here are some from Perl 5: An object is just a blessed referent. A class is just a package. A method is just a subroutine. We're modifying those ideas a bit in Perl 6, at least to the extent that we use different keywords, but the underlying concept is still there. But in Perl 6 we now also have things like: A Perl5 magic is just a property. A Perl5 attribute is just a property. A block is just a closure. A control structure is just a subroutine that can call closures. A switch is just a control structure that sets the topic. A case is just a smartmatch against the topic. An exception handler is just a switch with a funny topic. An exception handler is just a closure property. Anything like an exception handler is also just a closure property. Control flow is just a kind of exception. An object attribute is just an oddly scoped variable. A class attribute is just a package or lexical variable. A grammar is just a class. A grammar rule is just a method. A regex modifier is just a pragma. A type is just a property that's interpreted as a contract. A signature is just a way to bind a list to some names. A vector operator is just a "hyper" scalar operator. And maybe: A bitwise operator is just a logic operator scoped to a set of bits. That's why I can't accept a characterization of +& +| +X - bitwise operations on int +&= +|= +X= ~& ~| ~X - bitwise operations on str ~&= ~|= ~X= ?& ?| ?X - bitwise operations on booleans ?&= ?|= ?X= as UME (Unnecessary Multiplication of Entities). The things you see there aren't entities--rather, they're decomposable to entities that are reused from elsewhere. The *only* new thing is the grammar rule that says you can modify a logic operator with a context operator. I would submit that some_big_long_term ~| some_other_big_long_term is much clearer than ~some_big_long_term .| ~some_other_big_long_term because you have the same problem as when you move the parenthese out front of the function--the context is further away. Plus we still have to reason out what the polymorphic operator is going to do. I do realize that every time we say "an A is just a B", it's really a kind of fib, because they're all oversimplifications, particularly when the concept B is more complicated than the concept A. A closure is arguably harder to understand than a block, after all. But this is how I think, and Perl 6 is going to be full of it, one way or another. :-) Larry