> From: [EMAIL PROTECTED] (Karl M. Hegbloom)
> Date: 25 Dec 2002 14:39:40 -0800
>
> [I'm not on the list; please CC.]
>
> In Scheme, I can say:
>
> (cond
> ((predicate-expression) => (lambda (r) ...))
> (...))
>
> ... and the value returned by (predicate-expression) is passed as an
> argument to the lambda expression in the rhs. Sometimes this is very
> handy, since then I don't have to call on (predicate-expression)
> again, or create a (let ...) around it all to cause
> (predicate-expression) to only be computed once!
>
> I'd like to do the similar in Perl 6, where, for instance:
>
> if ($self->{obsoletes})
> {
> foreach (@{$self->{obsoletes}})
> {
> # do something with this $_
> }
> }
You mean, of course:
if $self{obsoletes}
{
for $self{obsoletes}
{
# Do something with $_
}
}
Just getting people used to P6 syntax. :)
> ... could become something more like:
>
> if ($self->{obsoletes}) =>
> {
> # $_ is now the value of "$self->{obsoletes}" as returned
> # above, never computed (or typed in) twice.
> #
> foreach (@{$_}})
> {
> # do something with this inner $_
> }
> }
I think this'll do it:
given $self{obsoletes}
{
# $_ is aliased to $self{obsoletes} now
when true
{
# This only executes if $_ is true
}
}
It's not the most concise thing in the world, but (since you were
referring to a C<cond> anyway) it will probably do.
I'm not sure if you can make C<if> topicalize using a pointy sub, but
if you can:
if $self{obsoletes} -> $_
{
# $_ is now aliased to $self{obsoletes}
# And this only executes if it's true
}
That would indeed be handy.
Luke