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

a constant hash does not coerce its RHS correctly #2682

Open
p6rt opened this issue Mar 23, 2012 · 8 comments
Open

a constant hash does not coerce its RHS correctly #2682

p6rt opened this issue Mar 23, 2012 · 8 comments
Labels
RFC Request For Comments

Comments

@p6rt
Copy link

p6rt commented Mar 23, 2012

Migrated from rt.perl.org#111944 (status was 'open')

Searchable as RT111944$

@p6rt
Copy link
Author

p6rt commented Mar 23, 2012

From @moritz

14​:37 < moritz> nom​: constant %h = 1, 2; say %h.WHAT
14​:37 <+p6eval> rakudo 4a247b​: OUTPUT«Parcel()␤»

should be Hash(), of course

14​:37 * moritz submits rakudobug
14​:37 < jnthn> Hm :)
14​:38 * jnthn wonders how that one is meant to work :)
14​:38 < jnthn> Though, constant %h = { ... } gets you what you want.
14​:38 < moritz> maybe like constant %h := (my % = ...)
14​:38 < jnthn> Or that.

@p6rt
Copy link
Author

p6rt commented Nov 20, 2013

From @masak

<japhb_> r​: constant %foo = ().list; say %foo.perl;
<camelia> rakudo-parrot 180fca, rakudo-jvm 180fca​: OUTPUT«().list␤»
<japhb_> ^^ Is that a bug, or me being silly?
<timotimo> it seems like both
<jnthn> japhb_​: It's me not really grokking how constant is meant to work and wanting a model rather than just hacking something... :)
<jnthn> japhb_​: So right now it doesn't impose any context or check anything...
<japhb_> Ah.
<tadzik> r​: my %foo = ("a", 5); say %foo.perl
<camelia> rakudo-parrot 180fca, rakudo-jvm 180fca​: OUTPUT«("a" => 5).hash␤»
<tadzik> looks legit to me
<tadzik> r​: my %foo = ("a", 5).list; say %foo.perl
<camelia> rakudo-parrot 180fca, rakudo-jvm 180fca​: OUTPUT«("a" => 5).hash␤»
<tadzik> oh
<jnthn> Oh...it does .hash it?
<tadzik> well, it's a hash container
<jnthn> I didn't now that :)
<tadzik> I'd expect that :)
<tadzik> but constant doesn't trigger it
<jnthn> Right, I just didn't think that it'd been tweaked to do it.
<jnthn> Oh...sorry, you wrote my
<jnthn> And I read constant.
<jnthn> Well, yeah, we could simply .list or .hash the RHS depending on sigil
<tadzik> r​: my constant %foo = ("a", 5).list; say %foo.perl
<camelia> rakudo-parrot 180fca, rakudo-jvm 180fca​: OUTPUT«("a", 5).list␤»
<tadzik> best of both worlds? :P
<masak> r​: my %h = 4
<camelia> rakudo-parrot 180fca​: OUTPUT«Odd number of elements found where hash expected [...]
<camelia> ..rakudo-jvm 180fca​: OUTPUT«Odd number of elements found where hash expected [...]
<masak> re constant hash​: I'd very much expect 'constant' to give the above warning just as much as 'my'.
* masak submits rakudobug
<FROGGS> masak++
<tadzik> r​: constant %h = 4
<camelia> rakudo-parrot 180fca, rakudo-jvm 180fca​: ( no output )
<tadzik> phihihi
<jnthn> That one is, like, so already in RT..
<masak> I will look for it.
<masak> p​: constant %h = 1, 2; say %h.WHAT
<camelia> rakudo-parrot 180fca​: OUTPUT«(Parcel)␤»
<masak> that's https://rt-archive.perl.org/perl6/Ticket/Display.html?id=111944
<masak> I will attach the current complaint to it.

@p6rt
Copy link
Author

p6rt commented Nov 20, 2013

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

@p6rt
Copy link
Author

p6rt commented Apr 7, 2016

From @diakopter

13​:08 <diakopter> m​: constant %h = 1, 2; say %h.WHAT
13​:08 <camelia> rakudo-moar 61d231​: OUTPUT«===SORRY!=== Error while compiling /tmp/NxuZQLpyx_␤Type check failed in
  constant declaration of %h; expected Associative but got List (List)␤at /tmp/NxuZQLpyx_​:1␤------>
  constant %h = 1, 2⏏; say %h.WHAT␤»

@p6rt
Copy link
Author

p6rt commented Apr 7, 2016

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

@p6rt
Copy link
Author

p6rt commented Apr 8, 2016

From @moritz

On Thu Apr 07 10​:10​:22 2016, diakopter wrote​:

13​:08 <diakopter> m​: constant %h = 1, 2; say %h.WHAT
13​:08 <camelia> rakudo-moar 61d231​: OUTPUT«===SORRY!=== Error while
compiling /tmp/NxuZQLpyx_␤Type check failed in
constant declaration of %h; expected Associative but
got List (List)␤at /tmp/NxuZQLpyx_​:1␤------>
constant %h = 1, 2⏏; say %h.WHAT␤»

This is not correct behavior; hash assignment is meant to be coercive, and I see no indication that doing it in a constant is supposed to be any diferent than in a regular my.

@p6rt
Copy link
Author

p6rt commented Apr 8, 2016

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

@p6rt
Copy link
Author

p6rt commented Sep 11, 2016

From @smls

Constant @​ variables behave differently from their `my` counterparts as well​:

  ➜ constant @​a = 1..3;
  ➜ say @​a.WHAT;
  (List)

Maybe the default types (which assignment coerces to) are supposed to be​:

  | @​ | %
  ----------+-------+------
  constant​: | List | Map
  my​: | Array | Hash

...and the `constant %` case just doesn't work correctly yet.

It would make sense, because List/Map are the immutable counterparts of Array/Hash.

But the design docs don't have much on constants, so I'm just guessing at the original intentions.

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

No branches or pull requests

1 participant