in reply to No braces

I didnt see this mentioned already so ill say it here: Dangling else!

if ($x==7) if ($x==8) $x=0 else $x=7

Which way to parse this? Is the else for the inner or outer if? Well, there are rules to disambiguate that are typical, I believe the else goes with the innermost if by convention for instance. But overall the simplest solution is to do away with the problem entirely. By saying that the result of a loop or conditional is ALWAYS a block you never have the problems that you encounter by saying it may be a statement OR a block.

And no, I bet you a hundred bytes that this wont change a bit. Larry was wearing his real smart hat when he made this rule up. Using statement modifiers he provided the statement form, and the rest uses the block form. They look different a bit, but thats the idea, they do slightly different things and thus they should look different.


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi


Replies are listed 'Best First'.
Re: No braces
by Abigail-II (Bishop) on Feb 11, 2004 at 19:37 UTC
    Of course, in perl6, you'd wish your parsing of if statements was as simple as dangling elses. In perl6:
    my %foo; if !%foo{die} {print "Yes"}; # Prints yes. if !%foo {die} {print "Yes"}; # dies.

    Larry was wearing his real smart hat when he made this rule up.
    Oh, he was, when he designed perl1 to perl5. But he's making up for it with his significant whitespace rules in perl6.

    Abigail

      Well, I dont use the extra whitespace as you do, but I have to say ive become quite accustomed to the parens required around an if. *shrug* Perl6 is a while before it makes into my production enviornment, so im not too fussed.

      But this whitespace issue really gets your goat eh Abigail? Heh.


      ---
      demerphq

        First they ignore you, then they laugh at you, then they fight you, then you win.
        -- Gandhi


        This all rather makes me appreciate the simplicity of lisp syntax. No precedence rules, no ambiguity and trivially easy for my editor to automatically indent correctly. That fact is very very useful. There's no need for a distinction between trinary if and if/else either - they are one and the same thing. I know the more 'textured' appearance of perl code helps to add visual distinctiveness and is a more natural way of expressing some things, but it sure is easy to edit lisp code with a good editor.

        I realise of course that lisp syntax (or lack thereof) is not to everyones taste though. By the way - I rather like the doSomething() if $condition; notation in perl - it seems to fit the way my brain works quite well for a lot of cases.

        With the significant whitespace perl6 syntax does seem to be heading in the direction of increased hairiness.