Advertisement
Guest User

Untitled

a guest
Oct 4th, 2011
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.49 KB | None | 0 0
  1. #!/usr/bin/env perl6
  2.  
  3. use v6;
  4.  
  5. sub swap(Array @xs is copy, $pos = 1) {
  6.   return @xs if +@xs <= 1;
  7.   @xs[$pos .. @xs.end].unshift(reverse @xs[0..$pos]);
  8. }
  9.  
  10. my @given = 1,3,5 ... 21;
  11. my @swapped = swap(@given, 2);
  12.  
  13. say "BEFORE :" ~ ~@given;
  14. say "AFTER  :" ~ ~@swapped;
  15.  
  16. [rml@glamdring mathoms]$ ./varfun.pl
  17. Nominal type check failed for parameter '@xs'; expected Positional[Array] but got Array instead
  18.   in 'swap' at line 5:./varfun.pl
  19.   in main program body at line 11:./varfun.pl
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement