Skip to content

inconsistent block/hash detection (again) #15918

Description

@p5pRT

Migrated from rt.perl.org#130958 (status was 'resolved')

Searchable as RT130958$

Activity

  1. p5pRT commented on Mar 8, 2017

    @p5pRT
    Author

    From @rjbs

    I realize that the block/hash issue has had a lot of ink spilled over it, but
    this particular example surprised and baffled me (and Matthew Horsfall, who
    pointed it out to me today)​:

      ~$ perl -MData​::Dumper -E 'say Dumper([ map {; { 1 => $_ } } qw(cat) ])'
      $VAR1 = [
      {
      '1' => 'cat'
      }
      ];

      ~$ perl -MData​::Dumper -E 'say Dumper([ map {; { $_ => 1 } } qw(cat) ])'
      $VAR1 = [
      'cat',
      1
      ];

    The inside {...} in these two are interpreted differently based on whether the
    first token is $_ or 1? On one hand, I wish these were consistent. On the
    other, I realize that this change might break some code somewhere.

    (Yes, I know you can force the issue with a unary plus.)

    --
    rjbs

  2. p5pRT commented on Mar 29, 2017

    @p5pRT
    Author

    From @iabyn

    On Wed, Mar 08, 2017 at 11​:13​:03AM -0800, Ricardo SIGNES wrote​:

    # New Ticket Created by Ricardo SIGNES
    # Please include the string​: [perl #130958]
    # in the subject line of all future correspondence about this issue.
    # <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=130958 >

    I realize that the block/hash issue has had a lot of ink spilled over it, but
    this particular example surprised and baffled me (and Matthew Horsfall, who
    pointed it out to me today)​:

    ~$ perl -MData​::Dumper -E 'say Dumper([ map {; { 1 => $_ } } qw(cat) ])'
    $VAR1 = [
    {
    '1' => 'cat'
    }
    ];

    ~$ perl -MData​::Dumper -E 'say Dumper([ map {; { $_ => 1 } } qw(cat) ])'
    $VAR1 = [
    'cat',
    1
    ];

    The inside {...} in these two are interpreted differently based on whether the
    first token is $_ or 1? On one hand, I wish these were consistent. On the
    other, I realize that this change might break some code somewhere.

    I don't see that as being particularly surprising. The rule appears to be​:
    if a literal constant follows the '{' it's probably a hash; if a variable
    follows the '{' its probably a block.

    --
    Little fly, thy summer's play my thoughtless hand
    has terminated with extreme prejudice.
      (with apologies to William Blake)

  3. p5pRT commented on Mar 29, 2017

    @p5pRT
    Author

    The RT System itself - Status changed from 'new' to 'open'

  4. p5pRT commented on Jul 7, 2017

    @p5pRT
    Author

    From @rjbs

    * Dave Mitchell <davem@​iabyn.com> [2017-03-29T09​:02​:57]

    The inside {...} in these two are interpreted differently based on whether
    the first token is $_ or 1? On one hand, I wish these were consistent. On
    the other, I realize that this change might break some code somewhere.

    I don't see that as being particularly surprising. The rule appears to be​:
    if a literal constant follows the '{' it's probably a hash; if a variable
    follows the '{' its probably a block.

    I guess the reason I was surprised is that I don't know what the rule is, nor
    could I find an explanation. I suppose I don't have any actual constructive
    suggestion to make, and maybe I should just henceforth write +{ much more
    often.

    If nobody else has a good idea for making this clearer in docs or anything
    else, let's close this ticket. :/

    --
    rjbs

  5. p5pRT commented on Jul 10, 2017

    @p5pRT
    Author

    From @xsawyerx

    On 07/07/2017 04​:46 PM, Ricardo Signes wrote​:

    * Dave Mitchell <davem@​iabyn.com> [2017-03-29T09​:02​:57]

    The inside {...} in these two are interpreted differently based on whether
    the first token is $_ or 1? On one hand, I wish these were consistent. On
    the other, I realize that this change might break some code somewhere.
    I don't see that as being particularly surprising. The rule appears to be​:
    if a literal constant follows the '{' it's probably a hash; if a variable
    follows the '{' its probably a block.
    I guess the reason I was surprised is that I don't know what the rule is, nor
    could I find an explanation. I suppose I don't have any actual constructive
    suggestion to make, and maybe I should just henceforth write +{ much more
    often.

    If nobody else has a good idea for making this clearer in docs or anything
    else, let's close this ticket. :/

    There's no reason to not make it clearer in the docs. Or, rephrasing​:
    let's make it clearer in the docs. No harm in that.

    Also​:

    $ perl -MData​::Dumper -E 'say Dumper([ map {; { "$_" => 1 } } qw(cat) ])'
    $VAR1 = [
      {
      'cat' => 1
      }
      ];

  6. p5pRT commented on Jul 10, 2017

    @p5pRT
    Author

    From zefram@fysh.org

    Ricardo Signes wrote​:

    I guess the reason I was surprised is that I don't know what the rule is, nor
    could I find an explanation.

    The actual rule is hideous. We shouldn't attempt to explain it; we should
    just document clearly how to force the interpretation ("+{" and "{;").
    We should also not make any change to the rule, for fear of breaking
    correct code.

    -zefram

  7. p5pRT commented on Jul 11, 2017

    @p5pRT
    Author

    From @demerphq

    On 11 Jul 2017 00​:22, "Zefram" <zefram@​fysh.org> wrote​:

    Ricardo Signes wrote​:

    I guess the reason I was surprised is that I don't know what the rule is,
    nor
    could I find an explanation.

    The actual rule is hideous. We shouldn't attempt to explain it; we should
    just document clearly how to force the interpretation ("+{" and "{;").
    We should also not make any change to the rule, for fear of breaking
    correct code.

    Hear hear. Abigail does this.

    Yves

  8. p5pRT commented on Aug 24, 2017

    @p5pRT
    Author

    From @Abigail

    On Tue, Jul 11, 2017 at 07​:05​:34PM +0200, demerphq wrote​:

    On 11 Jul 2017 00​:22, "Zefram" <zefram@​fysh.org> wrote​:

    Ricardo Signes wrote​:

    I guess the reason I was surprised is that I don't know what the rule is,
    nor
    could I find an explanation.

    The actual rule is hideous. We shouldn't attempt to explain it; we should
    just document clearly how to force the interpretation ("+{" and "{;").
    We should also not make any change to the rule, for fear of breaking
    correct code.

    Hear hear. Abigail does this.

    Only when Perl gets it wrong, of if I'm not sure Perl will get it right.

    Abigail

  9. p5pRT commented on Dec 5, 2017

    @p5pRT
    Author

    From zefram@fysh.org

    I wrote​:

                                                                we should
    

    just document clearly how to force the interpretation ("+{" and "{;").

    This is already documented pretty clearly in perlref(1). I've added a
    similar note to perlsyn(1), where it introduces the concept of a block,
    in commit 5577141. That should satisfy
    this ticket.

    -zefram

  10. p5pRT commented on Dec 8, 2017

    @p5pRT
    Author

    @iabyn - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions