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
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html
>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?
-- Rod Adams
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.
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
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