Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

S04 default { } bug?

已查看 0 次
跳至第一个未读帖子

Ilmari Vacklin

未读,
2005年10月24日 00:39:232005/10/24
收件人 perl6-l...@perl.org
Hi,

S04 says thus:

The default case:

default {...}

is exactly equivalent to

when true {...}

However, that parses to:

if $_ ~~ bool::true { ...; leave }

Which is not executed if $_ is false, unless ~~ bool::true does
something special. Perhaps default should be equivalent to:

when $_ { ... }

That is, $_ is always $_, so the block is always executed.

(It also strikes me that using booleans in when clauses could/should be
disallowed entirely.)

--
Ilmari Vacklin
(wolverian)

Luke Palmer

未读,
2005年10月25日 01:33:242005/10/25
收件人 perl6-l...@perl.org
On 10/23/05, Ilmari Vacklin <ilmari....@helsinki.fi> wrote:
> Hi,
>
> S04 says thus:
>
> The default case:
>
> default {...}
>
> is exactly equivalent to
>
> when true {...}
>
> However, that parses to:
>
> if $_ ~~ bool::true { ...; leave }
>
> Which is not executed if $_ is false, unless ~~ bool::true does
> something special.

Good catch. Given the discussions about given arglist pattern
matching, we may be able to make it:

when :(_) {...}

Or:

when -> _ {...}

And if not that, then this ought to work:

when ({ 1 }) {...}

(A nullary codeblock that is evaluated for truth).

Luke

Larry Wall

未读,
2005年10月25日 16:18:442005/10/25
收件人 perl6-l...@perl.org
On Mon, Oct 24, 2005 at 07:39:23AM +0300, Ilmari Vacklin wrote:
: Hi,

:
: S04 says thus:
:
: The default case:
:
: default {...}
:
: is exactly equivalent to
:
: when true {...}
:
: However, that parses to:
:
: if $_ ~~ bool::true { ...; leave }
:
: Which is not executed if $_ is false, unless ~~ bool::true does
: something special.

It did do something special at the time the Apocalypse was written,
but it was probably a bad idea. Smart match was going to recognize
obviously boolean expressions and just ignore the other argument.
The problem is that it's not always obvious what's obvious.

Larry

0 个新帖子