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

What is a "list"? #1344

Open
zoffixznet opened this issue Dec 28, 2017 · 6 comments
Open

What is a "list"? #1344

zoffixznet opened this issue Dec 28, 2017 · 6 comments
Labels
consensus needed Needs a well-versed decision with justification, possibly from a core developer

Comments

@zoffixznet
Copy link
Contributor

I'd assume it to be something that does Positional role. For example, @() coercer calls .cache, which on Seqs returns a List and on Anys calls .list.

I'd assume anything that is @()-coerced can be bound to a @-variable. However, that is not currently the case:

perl6 -e 'my @z := @(%(:42a))'
Type check failed in binding; expected Positional but got Seq ($((:a(42),).Seq))

The reason is Hash.list returns a Seq object. So the question is: is Seq a "list"?

Along with the above inconsistency, I see that Seq:D.list returns a List, while list Seq:D still returns a Seq. I went to fix that (currently in list-Seq branch in rakudo and roast), but that's blocked by a 6.c test of list that looks like it might've been changed to check for Seq return value by accident.

To summarize: what's a "list" and is Seq a "list"?

@zoffixznet zoffixznet added the consensus needed Needs a well-versed decision with justification, possibly from a core developer label Dec 28, 2017
@zoffixznet
Copy link
Contributor Author

Somewhat related Issue: #1345 Should @foo := Seq:D do PositionalBindFailover thing?

@jnthn
Copy link
Member

jnthn commented Dec 28, 2017

I'd expect .list to return something that does Positional, and List is usually a good choice (of course, if the thing is already a subclass of List, such as Array, that's perfectly fine too, and it certainly shouldn't upcast).

@jnthn
Copy link
Member

jnthn commented Dec 28, 2017

Should @foo := Seq:D do PositionalBindFailover thing?

No. := is the low-level bind operator. ::= arguably could.

@zoffixznet
Copy link
Contributor Author

Thanks. I'll go over and fix any .list's that don't return a Positional.

zoffixznet added a commit that referenced this issue Dec 31, 2017
Per #1344 , a Seq is not
a "list", because it does not do a Positional role.
zoffixznet added a commit to Raku/roast that referenced this issue Dec 31, 2017
Per rakudo/rakudo#1344 , a Seq is not
a "list", because it does not do a Positional role.

Looks like the original tests[^2] did start off testing for List and
because they were added alongside `cache` listop, they tested for
whether caching did not occur. Then, they were changed[^2] to test for
a Seq return value. My guess that was semi-accidental and the proper
course was meant to be to fix &list(Seq:D) to give a List.

[1] a046d7448847d327e09bc542dd
[2] 5463a12cbe6dacaaef898d28d3
zoffixznet added a commit to Raku/roast that referenced this issue Dec 31, 2017
Per rakudo/rakudo#1344 , a Seq is not
a "list", because it does not do a Positional role.

Looks like the original tests[^2] did start off testing for List and
because they were added alongside `cache` listop, they tested for
whether caching did not occur. Then, they were changed[^2] to test for
a Seq return value. My guess that was semi-accidental and the proper
course was meant to be to fix &list(Seq:D) to give a List.

[1] a046d7448847d327e09bc542dd
[2] 5463a12cbe6dacaaef898d28d3
@zoffixznet
Copy link
Contributor Author

Started writing tests and below is what I got so far... but there are several inconsistencies in &list that are caused by inconsistencies in +foo slurpies.

I opened that issue as #1355 and will wait for its resolution before proceeding here.

subtest 'list makes Positionals' => {
    plan 3 + my @stuff :=
        (1, (2, 3)), $(1, (2, 3)),
        %(:42foo, :70bar), $%(:42foo, :70bar), Map.new((:42foo, :70bar)),
        $(Map.new((:42foo, :70bar))),
        set(1, 2, 3), SetHash.new(1, 2, 3),
        bag(1, 2, 3), BagHash.new(1, 2, 3),
        mix(1, 2, 3), MixHash(1, 2, 3),
        1, <1>, 2e0, <2e0>, 3.1, <3.1>, <3+3i>, <3+3i >,
        Date.today, DateTime.now, now;

    subtest 'Seq' => {
        # Seqs are a bit of a strange animal when it comes to &list/.list:
        # https://irclog.perlgeek.de/perl6-dev/2017-12-31#i_15636448
        # Since they have the PositionalFailOver stuff, they can be considered
        # a "list" if you squint hard enough, so &list(Seq:D) is a no-op,
        # because it just passes through a `+@ is raw` slurpy, whereas `.list`
        # involves no such squinting and returns a real-er list
        plan 4;
        (my \V = (1, 2, 3).Seq).cache;
        isa-ok    list(V), Seq,    '&list returns a listy thing';
        is-deeply list(V), Seq,    '&list gives right list';
        isa-ok    V.list,  List,   '.list returns a listy thing';
        is-deeply V.list,  V.List, '.list gives right list';
    }

    subtest 'Array' => {
        plan 4;
        my \V = [1, 2, 3];
        isa-ok    list(V), Array, '&list returns a listy thing';
        is-deeply list(V), V,      '&list gives right list';
        isa-ok    V.list,  Array, '.list returns a listy thing';
        is-deeply V.list,  V,      '.list gives right list';
    }
    subtest 'Slip' => {
        plan 4;
        my \V = (1, 2, 3);
        isa-ok    list(V), Slip, '&list returns a listy thing';
        is-deeply list(V), V,      '&list gives right list';
        isa-ok    V.list,  Slip, '.list returns a listy thing';
        is-deeply V.list,  V,    '.list gives right list';
    }

    for @stuff -> \V {
        subtest V.^name => {
            plan 4;
            my \s-exp = (V ~~ Iterable and V.VAR !~~ Scalar) ?? (V,) !! V.List;
            isa-ok    list(V),   (V,), '&list returns a listy thing';
            is-deeply list(V),   (V,), '&list gives right list';
            isa-ok    V.list,    List, '.list returns a listy thing';
            is-deeply V.list,  V.List, '.list gives right list';
        }
    }
}

zoffixznet added a commit that referenced this issue Jan 7, 2018
Buf.list returns a Seq, which explodes when we rake its guts
for List stuff inside &nodemap.

Fix by making it return a List. Part of addressing
#1344

Bug find: https://irclog.perlgeek.de/perl6/2018-01-07#i_15660359
@zoffixznet
Copy link
Contributor Author

zoffixznet commented Mar 13, 2018

Related issue. there's a difference that a scalarized List doesn't get deconted by &list, but does by .list:

$ perl6 -e 'dd list $[1]; dd ($[1]).list'
($[1],)
[1]

And the same problem (or not problem?) exists with hash and pair coercers:

$ perl6 -e 'dd %$({:42foo}); '
Hash % = {:foo(42)}
$ perl6 -e 'dd hash $({:42foo}); '
Odd number of elements found where hash initializer expected:
Only saw: ${:foo(42)}
  in block <unit> at -e line 1

$ perl6 -e 'dd ($(:42foo)).Pair'
:foo(42)
$ perl6 -e 'dd pair $(:42foo)'
Too few positionals passed; expected 2 arguments but got 1
  in block <unit> at -e line 1

zoffixznet added a commit that referenced this issue Jun 17, 2018
Partially fixes R#1344 #1344

Since (per discussion on the Issue) a Seq is not a "list", the
.list/.cache methods need to return a Positional. This commit is
required for the grant to have proper coersion+typecheck
on `@`-sigilled constants. The rest of the Issue still requires
filling in the gaps in positional slurpy semantics
( R#1355 #1355 )
zoffixznet added a commit to Raku/roast that referenced this issue Oct 14, 2018
The link doesn't load anymore and R#1344 [^1] is still open.

[1] rakudo/rakudo#1344
ugexe pushed a commit to Raku/roast that referenced this issue Dec 15, 2018
ugexe pushed a commit to Raku/roast that referenced this issue Dec 15, 2018
The link doesn't load anymore and R#1344 [^1] is still open.

[1] rakudo/rakudo#1344
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus needed Needs a well-versed decision with justification, possibly from a core developer
Projects
None yet
Development

No branches or pull requests

2 participants