surprising consequences

0 views

Juerd

Apr 25, 2005, 3:05:49 PM4/25/05
to perl6-l...@perl.org
Assuming the following are true:

A: "if" is now a normal function

B: "foo() + 3" is (foo) + 3, foo doesn't get 3.

Then does that mean we're stuck with:

C: "if(\$foo) { say 'foo' }" being a syntax error?

I currently think A is wrong. Am I right?

Apr 25, 2005, 3:37:40 PM4/25/05
to perl6-l...@perl.org
Juerd wrote:

>Assuming the following are true:
>
> A: "if" is now a normal function
>
> B: "foo() + 3" is (foo) + 3, foo doesn't get 3.
>
>Then does that mean we're stuck with:
>
> C: "if(\$foo) { say 'foo' }" being a syntax error?
>
>I currently think A is wrong. Am I right?
>
>
>Juerd
>
>

There will always be various control constructs that cannot be written
as an equivalent function. Otherwise, there is no way to write the
higher level ones.

I suspect that "goto" and "if" are on this list. Possibly they are the
only things on this list, but "return" is a strong contender.

Additionally, any predicate form cannot be a "normal function". You
might be able to define an &infix:<for>, but getting to where you don't
need the {}'s on the LHS block, and getting a proper list on the RHS
gets rather abnormal.

Something that crossed my mind while writing this: Does

for { say } <== @a;

Work?

Juerd

Apr 25, 2005, 3:42:06 PM4/25/05
Rod Adams skribis 2005-04-25 14:37 (-0500):

> There will always be various control constructs that cannot be written
> as an equivalent function. Otherwise, there is no way to write the
> higher level ones.

Not a problem, because we're using something to bootstrap, and the perl
6 you'll be using to run your Perl 6 scripts will be in compiled form,
free of any need to parse itself.

Self-definition is a wonderful thing.

> Something that crossed my mind while writing this: Does
> for { say } <== @a;
> Work?

If for's just a function that takes a slurpy list, then I see no reason
why not.

Luke Palmer

Apr 25, 2005, 2:36:21 PM4/25/05
to Juerd, perl6-l...@perl.org
Juerd writes:
> Assuming the following are true:
>
> A: "if" is now a normal function

Almost. It's a statement-level form, which looks like a normal function
except for the statement: prepended on its name. Such constructs (which
include for, while, the whole gang) have a few special properties:

* They can't be used intra-expression.

say 3 + if foo() { 4 } else { 5 } # error!

* An opening brace anywhere (not inside brackets) in operator position
gets passed to them:

sub foo (*@_);
sub bar (*@_);

if foo 1, bar 2 { ... }
^ belongs to the if

You could use if() intra-expression like so:

say 3 + &statement<if else>().({foo()}):{4}:{5};

(Ick).

Luke

Larry Wall

May 3, 2005, 8:55:08 AM5/3/05
to perl6-l...@perl.org
On Mon, Apr 25, 2005 at 02:37:40PM -0500, Rod Adams wrote:
: Something that crossed my mind while writing this: Does

:
: for { say } <== @a;
:
: Work?

Nope. The brackets where a term is expected would be misconstrued
as an argument to the "for". Maybe we need an @= for a placeholder:

for @= { say } <== @;

Or maybe we could just make () serve that purpose:

for () { say } <== @;

Larry