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

List.Array loses Nil #6114

Open
p6rt opened this issue Mar 9, 2017 · 4 comments
Open

List.Array loses Nil #6114

p6rt opened this issue Mar 9, 2017 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 9, 2017

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

Searchable as RT130962$

@p6rt
Copy link
Author

p6rt commented Mar 9, 2017

From zefram@fysh.org

(Nil,).perl
(Nil,)
(Nil,).Array.perl
[Any]

The coercion from List to Array transforms the Nil element value into
an Any. This is a poor coercion. It is perfectly possible for an Array
to contain an element of Nil value, so the coercion ought to preserve
that value.

-zefram

@p6rt
Copy link
Author

p6rt commented Mar 9, 2017

From @lizmat

On 9 Mar 2017, at 12​:57, Zefram (via RT) <perl6-bugs-followup@​perl.org> wrote​:

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

(Nil,).perl
(Nil,)
(Nil,).Array.perl
[Any]

The coercion from List to Array transforms the Nil element value into
an Any. This is a poor coercion. It is perfectly possible for an Array
to contain an element of Nil value, so the coercion ought to preserve
that value.

$ 6 'my @​a = Nil; dd @​a'
Array @​a = [Any]

$ 6 'my @​a = (Nil,); dd @​a’ # more direct translation
Array @​a = [Any]

$ 6 'dd my @​ = (Nil,)'
Array @​ = [Any]

In all of these cases, Nil becomes Any after coercion.

The *only* way to keep Nil in here, is to make it the default​:

$ 6 'dd my @​ is default(Nil) = (Nil,)'
Array @​ = [Nil]

I’m not sure we want to do that for all Array coercions, or for all Array creation for that matter (seeing RT #​130963).

@p6rt
Copy link
Author

p6rt commented Mar 9, 2017

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

@p6rt
Copy link
Author

p6rt commented Mar 9, 2017

From zefram@fysh.org

Elizabeth Mattijsen via RT wrote​:

The *only* way to keep Nil in here, is to make it the default​:

There's also binding​:

my @​a; @​a[0] := Nil
Nil
@​a[0]
Nil

I'm not sure we want to do that for all Array coercions,

It's not required for all Array coercions. Only where there's a Nil
element value.

or for all Array creation for that matter (seeing RT #​130963).

That one's even more open. Although it's rather surprising behaviour
for the [] Array constructor to mangle Nil (since it doesn't overtly
involve assignment), I didn't commit to that being the part with the bug.
If you'd prefer for [] to keep the Nil manglement, it's open to Array.perl
to emit more complex code that doesn't just feed the Nil to [].

-zefram

@p6rt p6rt added the Bug 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