http://www.perlmonks.org?node_id=633938


in reply to Re: what would you like to see in perl5.12?
in thread what would you like to see in perl5.12?

Method names given as expressions ($foo->do{ EXPR }(LIST) instead of my $tmp=EXPR; $foo->$tmp(LIST) or $foo->${\(EXPR)}(LIST))
While I desired that too, but I can't think of a syntax that would be unambiguous:
I couldn't come up with any case where ->do{ was ambiguous. It's currently a syntax error.

Replies are listed 'Best First'.
Re^3: what would you like to see in perl5.12?
by blazar (Canon) on Aug 20, 2007 at 22:02 UTC
    I couldn't come up with any case where ->do{ was ambiguous. It's currently a syntax error.

    I hadn't considered the curlies: I had seen them but kinda not really noticed them. (It's been a terribly hard day.) If I take the curlies into account I get a very "unorthogonal" deviation from all the rest of Perl syntax I can think of. A bareword, with curlies next to it. And should whitespace be allowed between them? Or is do{ to be thought of as a single glyph? Anyway you think of it, it's very ugly.

      No, not a single glyph. Just a straightforward use of do BLOCK where it's not currently allowed.
        But then you have a bare arrow on the left. Let me see, you have a situation like:
        $foo -> THINGIE

        where THINGIE happens to be do BLOCK.

        With current syntax THINGIE can be:

        • a sub, array or hash dereferencing: (...), [...] and {...} respectively;
        • a bareword, interpreted like a method, with or without a pair of parens to pass parameters, if any: the latter, if present conveys a strong psychological feeling of being linked with the method itself as if they were a single thing;
        • a simple scalar value, to be interpreted as a symref (if not under strict) or a subref to be called like a method.

        All these thingies are "boxed", while yours look like the juxtaposition of two other thingies, with no surrounding box. It simply doesn't fit well, and is aesthetically unappealing.

        Granted, ->${\EXPR} looks awful, but it is an awful use of the existing syntax, which does not permit a more beautiful form. Your proposal makes for ugly syntax to start with: in all earnestness, looking at it from a distance it looks cleaner. But as you close up, you get an unsatisfactory feeling. Of course I would like to say that I have a much more beautiful proposal of my own, but no, I can't devise any...

        Update: striked out text above thanks to a /msg by ysth - "a simple scalar can always be a coderef or a method name (either qualified or not); the latter is unaffected by strict".