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

Re^5: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20 (*)

by ikegami (Pope)
on Nov 29, 2013 at 15:50 UTC ( #1064981=note: print w/ replies, xml ) Need Help??


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.

  • @{ ... } evaluates to an array, a list or a scalar.
  • @{ ... }[1,2] evaluates to a list or a scalar.
  • %{ ... }[1,2] evaluates to a list or a scalar.
  • %{ ... } evaluates to a hash, a list or a scalar.
  • *{ ... } 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

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

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


Comment on Re^5: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20 (*)
Select or Download Code
Re^6: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20 (*)
by BrowserUk (Pope) 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.
Re^6: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20 (demerphq mistaken?)
by shmem (Canon) 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.

        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'

        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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2014-09-17 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (56 votes), past polls