If topicalization

0 views
Skip to first unread message

Luke Palmer

unread,
Aug 3, 2005, 2:27:40 PM8/3/05
to perl6-l...@perl.org
I vaguely recall that we went over this already, but I forgot the
conclusion if we did.

In Damian and Larry's talk here at OSCON, I saw the example:

if foo() -> $foo {
# use $foo
}

How can that possibly work? If a bare closure { } is equivalent to ->
?$_ is rw { }, then the normal:

if foo() {...}

Turns into:

if foo() -> ?$_ is rw { }

And every if topicalizes! I'm sure we don't want that.

Luke

Stuart Cook

unread,
Aug 4, 2005, 4:45:04 AM8/4/05
to Luke Palmer, perl6-l...@perl.org
On 8/4/05, Luke Palmer <lrpa...@gmail.com> wrote:
> How can that possibly work? If a bare closure { } is equivalent to ->
> ?$_ is rw { }, then the normal:
>
> if foo() {...}
>
> Turns into:
>
> if foo() -> ?$_ is rw { }
>
> And every if topicalizes! I'm sure we don't want that.
>
> Luke


Here's one solution:

1) Bare blocks don't topicalise if you call them without an argument.

2) 'if' doesn't pass the value of the condition to its body, _UNLESS_
the body is incapable of accepting 0 arguments.


This means:

* The most common case, "if foo() { ... }", won't topicalise.

* If you /really/ want to access the value of the conditional, you can
say one of:
if foo() -> $_ { ... } # topicalise
if foo() -> $cond { ... } # don't topicalise
and 'if' will give it to you.

* The bare-block-to-pointy-sub rewrite rule is preserved, because a
bare block's parameter is optional.

Is there anything I've failed to take into account?


Stuart

Reply all
Reply to author
Forward
0 new messages