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

Slurpy array 'is copy' returns incorrectly. #545

Closed
p6rt opened this issue Dec 27, 2008 · 8 comments
Closed

Slurpy array 'is copy' returns incorrectly. #545

p6rt opened this issue Dec 27, 2008 · 8 comments

Comments

@p6rt
Copy link

p6rt commented Dec 27, 2008

Migrated from rt.perl.org#61772 (status was 'resolved')

Searchable as RT61772$

@p6rt
Copy link
Author

p6rt commented Dec 27, 2008

From publiustemp-perl6users@yahoo.com

  sub array_normal (@​array) {
  say sprintf "Array has %d elements and the first value is '%s'",
  @​array.elems, @​array[0];
  return @​array;
  }

  sub array_normal_copy (@​array) {
  say sprintf "Array has %d elements and the first value is '%s'",
  @​array.elems, @​array[0];
  return @​array;
  }

  sub array_slurpy (*@​array) {
  say sprintf "Array has %d elements and the first value is '%s'",
  @​array.elems, @​array[0];
  return @​array;
  }

  sub array_slurpy_copy (*@​array is copy) {
  say sprintf "Array has %d elements and the first value is '%s'",
  @​array.elems, @​array[0];
  return @​array;
  }

  my @​array = <a b c>;

  my @​new_array = array_normal(@​array);
  say @​new_array[0];

  @​new_array = array_normal_copy(@​array);
  say @​new_array[0];

  @​new_array = array_slurpy(@​array);
  say @​new_array[0];

  @​new_array = array_slurpy_copy(@​array);
  say @​new_array[0];

This outputs the following​:

  Array has 3 elements and the first value is 'a'
  a
  Array has 3 elements and the first value is 'a'
  a
  Array has 3 elements and the first value is 'a'
  a
  Array has 3 elements and the first value is 'a'
  a b c

So the "*@​array is copy" behaves like the rest when in the sub, but when returned, returns a single item.

Cheers.
Ovid

--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog - http://use.perl.org/~Ovid/journal/
Twitter - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6

@p6rt
Copy link
Author

p6rt commented Dec 28, 2008

From publiustemp-perl6users@yahoo.com

Forgot to add the revision and computer info​:

$ svn info; uname -a
Path​: .
URL​: https://svn.perl.org/parrot/trunk
Repository Root​: https://svn.perl.org/parrot
Repository UUID​: d31e2699-5ff4-0310-a27c-f18f2fbe73fe
Revision​: 34446
Node Kind​: directory
Schedule​: normal
Last Changed Author​: kjs
Last Changed Rev​: 34446
Last Changed Date​: 2008-12-27 21​:17​:55 +0000 (Sat, 27 Dec 2008)

Darwin curtis-poes-computer-3.local 9.5.1 Darwin Kernel Version 9.5.1​:
Fri Sep 19 16​:19​:24 PDT 2008; root​:xnu-1228.8.30~1/RELEASE_I386 i386

Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog - http://use.perl.org/~Ovid/journal/
Twitter - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6

@p6rt
Copy link
Author

p6rt commented Feb 13, 2009

From @jnthn

Hi,

OK, good news and bad. :-) Cutting down the example a tad for the
interesting bit​:

sub array\_slurpy \(\*@&#8203;array\) \{
    say sprintf "Array has %d elements and the first value is

'%s'",
@​array.elems, @​array[0];
return @​array;
}

sub array\_slurpy\_copy \(\*@&#8203;array is copy\) \{
    say sprintf "Array has %d elements and the first value is

'%s'",
@​array.elems, @​array[0];
return @​array;
}

my @&#8203;array = \<a b c>;

my @&#8203;new\_array = array\_slurpy\(@&#8203;array\);
say @&#8203;new\_array\[0\];

@&#8203;new\_array = array\_slurpy\_copy\(@&#8203;array\);
say @&#8203;new\_array\[0\];

This outputs the following​:

Array has 3 elements and the first value is 'a'
a
Array has 3 elements and the first value is 'a'
a b c

So the "*@​array is copy" behaves like the rest when in the sub, but
when returned, returns a single item.

OK, so now they give the same result, thanks to fixing a bug in 'is
copy' when handling arrays. Which is​:

  Array has 3 elements and the first value is 'a'
  a

However, I fear we may now have a bug in slurpy. Because if you pass an
array and you have a slurpy parameter, you should get an array of
arrays, the first element of the array of slurped parameters being the
array. And when it returns, I would expect that the you'd get the array
of arrays returned. So in fact I think the correct output for both of
these two with the slurpy maybe should be​:

  Array has 1 elements and the first value is 'a b c'
  a b c

Thoughts?

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Feb 13, 2009

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

@p6rt
Copy link
Author

p6rt commented Jul 13, 2009

From @kyleha

This is an automatically generated mail to inform you that tests are now available in b/t/spec/S06-signature/slurpy-params.t

@p6rt
Copy link
Author

p6rt commented May 31, 2010

From @moritz

Works now as expected, tests pass.

@p6rt
Copy link
Author

p6rt commented May 31, 2010

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed May 31, 2010
@p6rt
Copy link
Author

p6rt commented May 31, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S06-signature/slurpy-params.t

commit 42f8eb5b687cfa52c27468f0951a7716d1479144
Author​: moritz <moritz@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Mon May 31 19​:02​:27 2010 +0000

  [t/spec] test for RT #​61772, *@​a is copy messed up in Rakudo
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;31027 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S06-signature/slurpy-params.t b/t/spec/S06-signature/slurpy-params.t
index 4b8e748..f5d3440 100644
--- a/t/spec/S06-signature/slurpy-params.t
+++ b/t/spec/S06-signature/slurpy-params.t
@@ -302,6 +302,16 @@ eval_dies_ok 'sub rt65324(*@x, $oops) { say $oops }',
     is slurpy-by-name(:var<a v g>), 'a|v|g', 'Can call slurpy param by name';
 }
 
+# RT #61772
+{
+    sub array_slurpy_copy(*@a is copy) {
+        return @a;
+    }
+    my @array = <a b c>;
+    my @c = array_slurpy_copy(@array);
+    is @c[0], 'a', 'slurpy is copy-array works fine, thank you';
+}
+
 done_testing;
 
 # vim: ft=perl6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant