> On 23 Jul 2017, at 03:48, Zoffix Znet (via RT) <perl6-bugs-follo...@perl.org> 
> wrote:
> 
> # New Ticket Created by  Zoffix Znet 
> # Please include the string:  [perl #131783]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/Ticket/Display.html?id=131783 >
> 
> 
> The current behaviour kinda makes sense when you squint at it, but today we 
> had a user[^1]who was surprised by it, so I'm filing it as a ticket, if maybe 
> there's some Better Way this can be done with.
> 
> When you :delete an element from the Array, you get nqp::null stuffed into 
> the position, which gets converted to `is default` value when you look it up 
> again:
> 
>    <Zoffix__> m: use nqp; my @a is default(42) = <a b c>; @a[1]:delete; dd @a
>    <camelia> rakudo-moar b14721: OUTPUT: «Array @a = ["a", 42, "c"]␤»
> 
> However, if you now convert that Array to a Slip or a List, the hole is left 
> as a bare Mu and doesn't get turned into a default value, which is lost:
> 
>    <Zoffix__> m: use nqp; my @a is default(42) = <a b c>; @a[1]:delete; dd 
> @a.Slip
>    <camelia> rakudo-moar b14721: OUTPUT: «slip("a", Mu, "c")␤»
> 
>    <Zoffix__> m: use nqp; my @a is default(42) = <a b c>; @a[1]:delete; dd 
> @a.List
>    <camelia> rakudo-moar b14721: OUTPUT: «("a", Mu, "c")␤»
> 
> So it makes sense that without `is default` you don't get an `is default` 
> value, but at the same time, Mu is not a great value to deal with...
> 
> [1] https://irclog.perlgeek.de/perl6/2017-07-22#i_14908846

The problem is really caused by the fact that an Array has a descriptor, which 
contains the default value and type information, and a List does not.  And 
since a Slip isa List, we lose the descriptor when Slipping an Array.

The same issue appears with:

  $ 6 'my @a; @a[2] = 42; dd (|@a)[0] = 44; dd @a'
  Cannot modify an immutable Str (Nil)

Which is because Slip is a List, it uses List.AT-POS, and that one doesn’t 
create a WHENCE with a container to be filled at a later time.

Which then goes back to: what is the use case of Slipping an Array?  When do 
you need that?

Perhaps slipping an Array should produce a warning?

Reply via email to