Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove magic $/ shortcuts %() and @() #6287

Closed
p6rt opened this issue May 28, 2017 · 10 comments
Closed

Remove magic $/ shortcuts %() and @() #6287

p6rt opened this issue May 28, 2017 · 10 comments
Labels

Comments

@p6rt
Copy link

p6rt commented May 28, 2017

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

Searchable as RT131392$

@p6rt
Copy link
Author

p6rt commented May 28, 2017

From @briandfoy

It looks like %() with no characters between the parens creates a
Map, but if there's at least one character between the parens, it
creates a Hash. I figure all of these should create a Hash​:

  my %hash = %();
  put '1​: ', %hash.^name; # 1​: Hash

  my $hash-empty = %();
  put '2​: ', $hash-empty.^name; # 2​: Map

  my $hash-space = %( );
  put '3​: ', $hash-space.^name; # 3​: Hash

Where is %() documented (other than examples using it)?

  $ perl6 -v
  This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53-g66c6dda
  implementing Perl 6.c.

@p6rt
Copy link
Author

p6rt commented May 28, 2017

From @lizmat

On 28 May 2017, at 20​:56, brian d foy (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by "brian d foy"
# Please include the string​: [perl #​131392]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=131392 >

It looks like %() with no characters between the parens creates a
Map, but if there's at least one character between the parens, it
creates a Hash. I figure all of these should create a Hash​:

my %hash = %();
put '1​: ', %hash.^name; # 1​: Hash

my $hash-empty = %();
put '2​: ', $hash-empty.^name; # 2​: Map

my $hash-space = %( );
put '3​: ', $hash-space.^name; # 3​: Hash

FWIW, I have not been able to reproduce it, not on 2017.04.3 or HEAD or even 2015.12. So I find all of this rather strange :-)

@p6rt
Copy link
Author

p6rt commented May 28, 2017

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

@p6rt
Copy link
Author

p6rt commented May 28, 2017

From @zoffixznet

On Sun, 28 May 2017 11​:56​:51 -0700, comdog wrote​:

It looks like %() with no characters between the parens creates a
Map, but if there's at least one character between the parens, it
creates a Hash. I figure all of these should create a Hash​:

my %hash = %();
put '1​: ', %hash.^name; # 1​: Hash

my $hash-empty = %();
put '2​: ', $hash-empty.^name; # 2​: Map

my $hash-space = %( );
put '3​: ', $hash-space.^name; # 3​: Hash

Where is %() documented (other than examples using it)?

$ perl6 -v
This is Rakudo version 2017.04.3 built on MoarVM version 2017.04-53-
g66c6dda
implementing Perl 6.c.

Failing to reproduce this on any of the versions, including the one mentioned in OP.

Is this being run in REPL? Do you have some modules loaded? (if in REPL, do you have Readline or Linenoise installed?)

@p6rt
Copy link
Author

p6rt commented May 29, 2017

From @raiph

The token `%()` isn't an empty hash, it's a synonym for `%$/` or `$/.hash`.

'foo' ~~ /$<bar>=.*/; say %(); # Map.new((​:bar(Match.new...

Similarly, `@​()` is a synonym for `@​$/` or `$/.list`.


These tokens are documented at https://docs.perl6.org/language/variables#index-entry-variable_%24%3Cnamed%3E-variable_%2525%28%29-Named_Attributes


If there hasn't been significant adoption of these tokens in extant code then I'd personally +1 deprecation of them in v6.d in favor of `%$/` and `@​$/`.

@p6rt
Copy link
Author

p6rt commented May 29, 2017

From @zoffixznet

On Sun, 28 May 2017 18​:18​:14 -0700, raiph wrote​:

If there hasn't been significant adoption of these tokens in extant code then I'd personally +1 deprecation of them in v6.d in favor of `%$/` and `@​$/`.

+1. Even knowing $() was special, it didn't occur to me %() and @​() could be special too. While $() saves some typing, the %() vs %$/ are no win IMO.

I listed removal as a proposal in 6.d doc​: https://github.com/perl6/specs/blob/master/v6d.pod

Renaming this ticket to @​LARRY/6.d RFC

@p6rt
Copy link
Author

p6rt commented May 29, 2017

From @briandfoy

I did pull my first example out of a slightly larger program I was
playing with, but I thought that a match would surely have no effect.
Stupid me, because I've been around long enough to know that
assumption is almost always false. That "harmless" thing you leave out
is the actual problem. Here's a complete program that reproduces it​:

  'abcdef' ~~ m/ cd /;

  my $thingy = %();
  put $thingy.^name; #Map

@p6rt
Copy link
Author

p6rt commented May 29, 2017

From @lizmat

On 29 May 2017, at 18​:26, brian d foy <brian.d.foy@​gmail.com> wrote​:
I did pull my first example out of a slightly larger program I was
playing with, but I thought that a match would surely have no effect.
Stupid me, because I've been around long enough to know that
assumption is almost always false. That "harmless" thing you leave out
is the actual problem. Here's a complete program that reproduces it​:

'abcdef' ~~ m/ cd /;

my $thingy = %();
put $thingy.^name; #Map

Well, do we consider the named matches of a match modifiable or not? Feels to me having it as an (immutable) Map feels actually closer to the intent, rather than it being a (modifiable) Hash. It also gives more opportunity for optimization.

So perhaps the Hashes should be considered the odd ones out?

Liz

@p6rt
Copy link
Author

p6rt commented Jun 23, 2018

From @AlexDaniel

Further discussion on rakudo/rakudo#1946

On 2017-05-28 21​:20​:08, cpan@​zoffix.com wrote​:

On Sun, 28 May 2017 18​:18​:14 -0700, raiph wrote​:

If there hasn't been significant adoption of these tokens in extant
code then I'd personally +1 deprecation of them in v6.d in favor of
`%$/` and `@​$/`.

+1. Even knowing $() was special, it didn't occur to me %() and @​()
could be special too. While $() saves some typing, the %() vs %$/ are
no win IMO.

I listed removal as a proposal in 6.d doc​:
https://github.com/perl6/specs/blob/master/v6d.pod

Renaming this ticket to @​LARRY/6.d RFC

@p6rt p6rt closed this as completed Jun 23, 2018
@p6rt
Copy link
Author

p6rt commented Jun 23, 2018

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

@p6rt p6rt added the at_larry label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant