Ticket #538 (closed bug: invalid)

Opened 5 years ago

Last modified 5 years ago

NQP list initializers

Reported by: bsdz Owned by:
Priority: normal Milestone:
Component: nqp Version: trunk
Severity: medium Keywords:
Cc: pmichaud Language:
Patch status: Platform: all

Description

When a list is declared in NQP with only one element a scalar is created.

i.e, the following nqp script: -

load_bytecode('library/dumper.pbc');

my @my_list := (10);
_dumper(@my_list, 'my_list');

displays: -

"my_list" => 10

when it should show: -

"my_list" => ResizablePMCArray (size:1) [
    10
]

A workaround is to place a dummy element and shift it. i.e.

my @my_list := ('dummy', 10);
@my_list.shift();
_dumper(@my_list, 'my_list');

Change History

Changed 5 years ago by jkeenan

  • cc pmichaud added

Patrick,

Can you comment on the issues raised in this ticket?

Thank you very much.
kid51

Changed 5 years ago by pmichaud

  • status changed from new to closed
  • resolution set to invalid

Short answer: Parens are not used to create lists or arrays in NQP (or Perl 6) -- that's the role of the comma.

In nqp-rx (the new version of NQP), one can force array creation by using square brackets, as in

my @list := [10];

Closing ticket,

Pm

Note: See TracTickets for help on using tickets.