HaloO,
On Saturday, 31. July 2010 18:56:47 David Green wrote:
> On 2010-07-31, at 1:33 am, Moritz Lenz wrote:
> > sub test() { True };
> > given 0 { when test() { say "OH NOEZ" } }
> > I don't think it's unreasonable to expect the output to be "OH NOEZ".
How does this relate the given to the when? If I get you right the
given is completely ignored and the truth of test() gives "OH NOEZ".
I think the given must determine the result.
> It's not unreasonable, especially if that's what you expect. But it's even
> more reasonable to expect this to work: given $something {
> when True { say "That's the truth!" }
> when 42 { say "Good answer!" }
> when "viaduct" { say "You guessed the secret word!" }
> }
Here I expect the $something to *select* one of the alternatives.
It can't be that a literal True ignores the given and just executes
the block.
> In both these examples, the intent is fairly clear from the context. It's
> easier to forget that Bools behave differently from other types when you
> only have some variable that could be any type: if $guess ~~ $answer { say
> "Correct!" } # hope your question wasn't T/F!
>
> Maybe we can't please everyone, but we can at least try not to displease
> anyone. Perl is awfully clever at keeping your eaten ponies, and there is
> a way we can have both the "helpful" syntax and the "consistent" one:
>
> given $who-knows-what {
> when True { say "It's a true thing!" }
> when 42 { say "It's numbery!" }
> whenever timeout() { say "Who cares what you say, time's up!" }
> whenever $override { say "Whatever, switching to automatic
> override" }
> }
Am I getting your intention to be that when honors the given and whenever just
checks truth? Couldn't we use if for this? That would avoid the new keyword.
Regards, TSa.
--
"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12 -- Srinivasa Ramanujan