A few, hopefully relevant thoughts (some of them).
Bryan C. Warnock wrote:
>--------------------------
>
>Perl 6 Reference - Statements and Blocks
>(0.1/2001-09-01)
A beauty to behold, this!
>Syntax Overview
>
>Keywords
> continue, do, else, elsif, for, foreach, given, goto, grep, if, last,
> map, next, redo, sort, sub, unless, until, when, while
We will be adding 'try' & 'catch'. 'finally' also? (or 'finalize' :-)
>Conditional Statement Modifiers
>
> 6. [ LABEL: ] expr if expr;
> 7. [ LABEL: ] expr until expr;
Should it be impossible to chain these? I wouldn't very much want to
maintain a program containing many of these, but I miss it occasionally when
hacking away, and I keep adding modifiers and checks. Eventually I want to
modify a modified statement, get annoyed, and make an enclosing block.
>Conditional Block Constructs
[...]
>16. [ LABEL: ] when expr : { block } # Note 5
>[Note 5. 'when' is only a valid construct when directly within a 'given'
> construct.]
Someone talked about given(expr) getting to be the same as for $_ (scalar
expr). (Couldn't find that mail in my mailbox, wierd?). Perhaps with an
added check that expr is actually a reference (though I can't really see
why, unless for a bit of good old B&D).
Wouldn't that be nice? That kind of simplicity I find particularly
attractive. I remember when learning perl several years ago, how glad I was
when I discovered how flat and simple everything was, that inheritance was
just qw(-> @ISA) (at least it seemed like that back then) and that parameter
just got passed in a global array (gee, was I wrong!). But I digress...
>Looping Block Constructs
>
>17. [ LABEL: ] while ( expr ) { block } [ continue { block } ]
>18. [ LABEL: ] until ( expr ) { block } [ continue { block } ]
>19. [ LABEL: ] for[each] ( expr; expr; expr ) # Note 4
> { block }
<speculation type="wild">
Makes me think how hard it would be to implement these in pure perl.
Something like:
sub my_while ((EXPR $expr) CODE $block ; CODE $continue) {
my $scope = new Scope;
my sub expr = $scope->eval_string($expr);
AGAIN:
goto END if ! expr();
$scope->eval_code($block);
$scope->eval_code($continue) if $continue;
goto AGAIN;
END:
}
sub continue (CODE $block) {
return $block;
}
Ok, I just wanted to demonstrate a funny prototype pattern, the
semi-reimplementation of while() is there because it is sunday and my
girlfriend is visiting her parents (- it is quite broken in regard to
lexical variable visibility. Does this absolutely require syntax filter or a
brand new parser, or can we do something clever?).
Also I find:
sub expr = $code_ref;
pretty cute, having p5 compiletime/runtime semantics similar to:
sub expr; *expr = $code_ref;
</speculation type="wild">
>Subroutine Code Blocks # Note 6
>
>21. sub identifier [ ( prototype ) ] [ :properties ] { block }
>22. sub [ ( prototype ) ] { block } # Note 7
Is it on purpose that coderefs can't have properties? This goes back to
variable/value properties. I never liked value properties very much, but
while it seems that ':inline' and ':multi' don't make a lot of sense here,
':memoized' does.
So we should have:
22. sub [ ( prototype ) ] [ :value_properties ] { block }
22. sub [ ( prototype ) ] { block } [ :value_properties ] # Or better?
best regards,
d.
ps. I don't really know how I can explain, but it filles me with joy to see
the activity on this list!
--
davíð helgason
co-founder & -der
panmedia aps