Nathan de Vries wrote:
> Sounds similar to the splat operator of Ruby:
> 
>      def foo(first, second, *rest)
>        puts first, second, rest.inspect
>      end
> 
>      foo(1,2)
>      => 1 2 []
> 
>      foo(1,2,3,4,5)
>      => 1 2 [3, 4, 5]
> 
>      rest = [3,4,5]
>      foo(1,2, *rest)
>      => 1 2 [3, 4, 5]
> 
>      rest = [3,4,5]
>      foo(1,2, rest)
>      => 1 2 [[3, 4, 5]]

Right, as well as:

   rest = [1,2,3,4,5]
   foo(*rest)
   => 1 2 [3, 4, 5]
   all = [0, *rest]
   => [0, 1, 2, 3, 4, 5]

and...
   irb(main):001:0> a = [1,2,3]
   => [1, 2, 3]
   irb(main):002:0> b,*c = a
   => [1, 2, 3]
   irb(main):003:0> b
   => 1
   irb(main):004:0> c
   => [2, 3]
   irb(main):005:0> case 2
   irb(main):006:1> when 0,*a
   irb(main):007:1>   puts 'yep'
   irb(main):008:1> end
   yep
   => nil

The splat operator splats into argument lists, array literals, etc.  It 
also collects over parameter lists, multiple assignment, cases... I 
think just about anywhere where ExpressionList is valid.  (I'm not sure 
we want to go that far... just saying.)

Chris
_______________________________________________
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss

Reply via email to