rakudo icon indicating copy to clipboard operation
rakudo copied to clipboard

Add ValueList as a 6.e feature in core

Open lizmat opened this issue 2 years ago β€’ 6 comments

Raku needs a value-type object for lists. This copies the ValueList ecosystem module https://raku.land/zef:lizmat/ValueList verbatim and makes it part of 6.e. It does NOT provide any additional syntactic sugar to easily create ValueLists, so ValueList.new(...) is the way to go now.

lizmat avatar Jan 04 '24 11:01 lizmat

As syntactic sugar for ValueLists, I would suggest ⁅ ⁆, basically:

sub circumfix:<⁅ ⁆>(\a) { ValueList.new(a) }

Allowing ⁅1,2,3⁆ as a value type.

I would propose to implement this in RakuAST only: this would allow it to be properly handled at compile time and produce WVals if all elements in a ValueList are constants (aka: can be literalized).

lizmat avatar Jan 04 '24 12:01 lizmat

I don't think discussing a new operator here would be a good idea. And I anticipate a dispute because ⁅ ⁆ pair has two major drawbacks.

First, it's a Unicode which is barely easy to use. A no good thing for something that is likely to be used on a very regular basis.

Second, the pair resembles array operator which is, apparently, has quite the opposite semantics.

vrurg avatar Jan 04 '24 14:01 vrurg

I don't think discussing a new operator here would be a good idea

I see it as brain-storming at this point, as any real discussion will be moot without this PR (or a functional equivalent thereof) being merged.

anticipate a dispute because ⁅ ⁆ pair has two major drawbacks

Perhaps ((...)) would be good syntactic sugar. With βΈ¨...βΈ© as the Unicode equivalents.

use ValueList;
sub circumfix:<(( ))>(\a) { ValueList.new(a) };
dd ((1,2,3)).WHICH;   # ValueObjAt.new("ValueList|C97F62DE1BA14379F6F017F3DFCBF16FB199D041")
dd Map.new(("a",42)); # Map.new((:a(42)))

lizmat avatar Jan 04 '24 16:01 lizmat

((1 + 2) * 3)

On Thu, Jan 4, 2024 at 8:14β€―AM Elizabeth Mattijsen @.***> wrote:

I don't think discussing a new operator here would be a good idea

I see it as brain-storming at this point, as any real discussion will be moot without this PR (or a functional equivalent thereof) being merged.

anticipate a dispute because ⁅ ⁆ pair has two major drawbacks

Perhaps ((...)) would be good syntactic sugar. With βΈ¨...βΈ© as the Unicode equivalents.

use ValueList;sub circumfix:<(( ))>(\a) { ValueList.new(a) };dd ((1,2,3)).WHICH; # ValueObjAt.new("ValueList|C97F62DE1BA14379F6F017F3DFCBF16FB199D041") dd Map.new(("a",42)); # Map.new((:a(42)))

β€” Reply to this email directly, view it on GitHub https://github.com/rakudo/rakudo/pull/5510#issuecomment-1877367694, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABHSYXB2TIKMR3SCBUGTMLYM3IOFAVCNFSM6AAAAABBMZ3ECCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZXGM3DONRZGQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

TimToady avatar Jan 06 '24 17:01 TimToady

use ValueList;
sub circumfix:<(( ))>(\a) { ValueList.new(a) };
say ((1 + 2) * 3);
Unable to parse expression in circumfix:sym<(( ))>; couldn't find final '))' (corresponding starter was at line 6)
at ...:3
------> say ((1+2⏏) * 3);

meh :-) So ((...)) it won't be.

lizmat avatar Jan 08 '24 10:01 lizmat

I can't concentrate on this matter deep enough to come out with a worthwhile proposal, but what I currently see is that the entire field of de-/containerization is not covered by unified Raku syntax. Basically, all we currently have are ops for itemizing with $ and deconting with <>, but both are targeting individual objects and do not propagate to collection types. Besides, I remember some complains about the weirdness of <> operator as its semantics has nothing in common with <key> hash access form.

The direction I'm looking at is based on <> (until a better replacement is found). What we can do is to use the decont operator (whatever it is) to mark the existing collection creation circumfixes in order to produce value counterparts of hashes and lists. Something like:

  • ValueList: (<> $a, $b, $c), unicode: ⦇ $a, $b, $c ⦈
  • ValueMap: {<> :$a, :$b, :$c }, %(<> :$a, :$b, :$c ), unicode: ⦃ :$a, :$b, :$c ⦄

Apparently, %(<> is gross, but if decont operator is considered as a modifier then things are looking less horrible.

vrurg avatar Jan 08 '24 15:01 vrurg