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


in reply to Re^4: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20 (*)
in thread use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20

I am with demerphq on that: It breaks the original model of sigils completely.

Except demerphq is mistaken. Perl5 sigils don't denote the type of result that will be returned.

so

You already have to locate the end of the expression. Nothing's been broken.

Replies are listed 'Best First'.
Re^6: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20 (demerphq mistaken?)
by shmem (Chancellor) on Nov 29, 2013 at 23:50 UTC
    Except demerphq is mistaken. Perl5 sigils don't denote the type of result that will be returned.

    Of course they do, at least since perl4 patchlevel 36 (or 19 on Atari). The result of the evaluation of an identifier with its sigil may be coerced to something diferent depending on the context in which that evaluation is effective, but the evaluation of an identifier bare of any context depends on its sigil. If that were not the case, sigils would be pointless.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

      The exception would be method calls.

      $object->foo() # $-sigil, but does this return a scalar?

      Obviously this is bracketed as:

      ($object)->foo()

      ... so the sigil does make sense: that particular subexpression returns a scalar. However, the expression as a whole could return a list.

      Some people argue that method calls should always return a scalar; if you need to return more than one result, return an arrayref.

      use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

        Some people argue that method calls should always return a scalar; if you need to return more than one result, return an arrayref.

        Ironically, these are the people who would benefit the most from ->@*.

      The result of the evaluation of an identifier with its sigil may be coerced to something diferent depending on the context in which that evaluation is effective

      That's not how context works at all, but even if you only consider list context, you still have:

      • @{ ... } evaluates to an array or a list.
      • @{ ... }[1,2] evaluates to a list.
      • %{ ... }[1,2] evaluates to a list.
      • %{ ... } evaluates to a hash or a list.
      • *{ ... } returns a scalar (glob).
      • *{ ... }{ARRAY} returns a scalar (reference).
      • &{ ... } can evaluate to a list or a scalar.
      • ${ ... }->() can evaluate to a list or a scalar.

      so in list context,

      • @... can evaluate to an array or a list.
      • %... can evaluate to an hash or a list.
      • $... can evaluate to a list or a scalar.
      • &... can evaluate to a list or a scalar.
      • *... can evaluate to a glob or a reference.

      Of course they do, at least since perl4 patchlevel 36 (or 19 on Atari).

      I can't verify that claim, but I doubt it. At the very least, it hasn't been the case since 5.6 which was released 14 years ago. There is not a single sigil that indicates the type of the value returned.

      the evaluation of an identifier bare of any context depends on its sigil.

      Noone said otherwise. Of course it depends on the sigil. @a is not the same as $a.

      The premise demerphq put forth is that the sigil is an indicator of the type of value to which the sigiled expression evaluates to. That's clearly not the case. You can't break a model that doesn't exist.

        Anyone care to shed light on why ikegami's post received so many downvotes?

        Is there a mistake in his overview of the return types of sigil'ed expressions, or in his general conception of Perl contexts and lists?
        I'm asking because my own conception matches what he wrote, so if it's wrong I'd be interested in learning why.

        That's not how context works at all

        I'm baffled. So you are telling me that I don't know about context in Perl?

        • %{ ... } evaluates to a hash or a list.

        And how, pray, is the "or" resolved? There.

        Anyways, you are right. Im sick of tennis match like conversations. I'm not here to win.

        perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^6: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20 (*)
by BrowserUk (Patriarch) on Nov 29, 2013 at 16:14 UTC
    %{ ... }[1,2] evaluates to a list or a scalar.

    That doesn't evaluate to anything, it is a syntax error.

    And the rest of the post is a straw man.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      it is a syntax error.

      Depends on your version of Perl. It's called a index-value slice. It returns key,val,key,val,...

      And the rest of the post is a straw man.

      Showing that sigils don't indicate the type of value returned is not a straw many to disproving that sigils indicate the type of the value returned.

        it is a syntax error.

        Depends on your version of Perl. It's called a index-value slice. It returns key,val,key,val,...

        Really? In which release of perl did that work then?:

        C:\test>\perl5.18\bin\perl -E"my %h=1..10; my $r = \%h; print %{ $r }[ + 1,2 ];" syntax error at -e line 1, near "}[" Execution of -e aborted due to compilation errors. C:\test>\perl5.18\bin\perl -E"my @a=1..10; my $r = \@a; print %{ $r }[ + 1,2 ];" syntax error at -e line 1, near "}[" Execution of -e aborted due to compilation errors.

        Or is this a preview of Yet Another Mis-Feature that'll have to be deprecated in a year or so?

        It will be sad indeed to see Perl die as a result of self-inflicted injuries.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.