Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: Perl oddities ("if" w/o parens)

by tye (Sage)
on Mar 01, 2005 at 23:23 UTC ( [id://435647]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Perl oddities
in thread Perl oddities

If you don't like leaving off the parens, then don't. They are becoming optional, not illegal.

I'm not actually certain that you misunderstood that. I feel a bit like you've talked all around the point but I'm left guessing what your primary point was. But it sure feels like you got the impression that

if( CONDITION ) { CODE }

would no longer be supported in Perl 6.

So if that wasn't your premise, I apologize for not getting your point.

In any case, I suspect that most people won't be dropping the parens much -- based on my impression that most people don't currently drop the optional parens from

STATEMENT if CONDITION;

(like I usually do) and my agreement with you that dropping the former parens will be rather jarring in relation to similar languages (both Perl5 and non-Perl languages).

- tye        

Replies are listed 'Best First'.
Re^5: Perl oddities ("if" w/o parens)
by Tanktalus (Canon) on Mar 02, 2005 at 00:30 UTC

    "jarring". That one word pretty much summed up my rambling. Thanks!

      Well, there's jarring, and then there's jarring. There's a qualitative difference between driving into a brick wall vs. driving over those same thousand bricks scattered over the road. We're aiming more for the latter effect. That's just one of the reasons we're not renaming Perl to something else, because that would make the transition look more like a brick wall. Another reason is that we don't want to waste a perfectly good four-letter word that googles well and has even been installed in the OED. A third reason is that we're not actually changing the most fundamental aspect of Perl, which is its basis in how natural languages work. If anything, we're just reinterpreting what that means to make it more true of Perl.

      But yes, we expect the migration process to be a little jarring in spots. We'll do what we can to keep the bricks spread out.

        Here's one monk who can't wait to be jarred by Perl 6. If you see Larry, pass on my thanks for taking the time to answer questions on perlmonks.org! ;-)

        [Jon]

Re^5: Perl oddities ("if" w/o parens)
by lidden (Curate) on Mar 01, 2005 at 23:50 UTC
    He said:
    I'm not saying that perl6 in general (or making parens optional in + specific) is a bad idea.
    so I think hi got it.

    I think it is great to get rid of the ()'s. I am still not sure if i like the new scoping rules though.
    if my ($i) = / ^ (f+) / { # Do stuff } say $i; # $i still defined.
    Good, Bad, Ugly... ?
      The scoping rules are much simpler now. And because blocks are closures, you can pass parameters to them, which are scoped to the block. So you could write your statement like this:
      if /^ (f+) / -> *$i { # Do stuff }
      where the * on the parameter list treats the pattern match result as binding to a list value, so the search result acts like a list value and binds $1 to $i. And arguably it's more readable because it puts the first thing that happens, the pattern match, out front. The parameter binding only happens if the pattern match succeeds.

      Or look at it another way. Suppose you run into a new control construct:

      frob my $x = bar() {...}
      Tell me quick whether $x is local to that block? In the Perl 5 world, you don't know for sure, because the scoping rules are arbitrary, and change between builtins and user-defined control verbs. In the Perl 6 world you know it isn't local, because the my isn't inside the block. Period. On the other hand, if you see
      frob bar() -> $x {...}
      then you absolutely know that $x is local because it's explicitly being passed as a parameter.

      I think people who initially perceive this as Bad or Ugly will eventually come around to seeing it as Kinda Pretty.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://435647]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2024-04-25 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found