develooper Front page | perl.perl6.language | Postings from July 2005

Do slurpy parameters auto-flatten arrays?

Thread Next
From:
Ingo Blechschmidt
Date:
July 26, 2005 13:54
Subject:
Do slurpy parameters auto-flatten arrays?
Message ID:
dc67qq$fjb$1@sea.gmane.org
Hi,

are the following assumptions correct?

  sub foo (*@args) { @args[0] }

  say ~foo("a", "b", "c");     # "a"

  my @array = <a b c d>;
  say ~foo(@array);            # "a b c d" (or "a"?)
  say ~foo(@array, "z");       # "a b c d" (or "a"?)
  say ~foo(*@array);           # "a"
  say ~foo(*(@array, "z"));    # "a"
 

  sub bar (*@args) { +@args }

  say bar(1,2,3);              # 3
  say bar(@array);             # 1 (or 4?)
  say bar(@array, "z");        # 2 (or 5?)
  say bar(*@array);            # 4


--Ingo

-- 
Linux, the choice of a GNU | There are no answers, only
generation on a dual AMD   | cross-references.  
Athlon!                    |


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About