_* in XML pattern match

Hello,   What is _* in the following expression? A language syntax? Or something else?   scala> <a>b<c/></a> match { case <a>{ x @ _* }</a> => x }
res3: Seq[scala.xml.Node] = ArrayBuffer(b, <c></c>)
Regards, Grzegorz Balcerek  

Re: _* in XML pattern match

_ * tells the compiler that the argument is to be treated as a
sequence of object and not as a single object.

if you do case x and x is Seq[Any] then how should the compiler
know if you want the object Seq[Any] or if you want a sequence of
Anys? The _* annotates it so that it is clear.

The same goes if you have a variable argument list and you want to pass it on

e.g.

def test(args: String*) = {
doSomething(args) // this passes args as a single object to
doSomething so it prints 1
doSomething(args: _*) // this passes args as a sequence to
doSomething so it prints args.length
}

def doSometing(args: String*) {
println(args.length)
}

-Stefan

2010/10/26 Grzegorz Balcerek :
> Hello,
>
> What is _* in the following expression? A language syntax? Or something
> else?
>
> scala> b match { case { x @ _* } => x }
> res3: Seq[scala.xml.Node] = ArrayBuffer(b, )
> Regards,
> Grzegorz Balcerek
>

Re: _* in XML pattern match

"Grzegorz Balcerek" wrote:
> What is _* in the following expression? A language syntax? Or
> something else?
>
> scala> b match { case { x @ _* } => x }
> res3: Seq[scala.xml.Node] = ArrayBuffer(b, )

Hi,

I think "8.1.9 Pattern Sequences" in the Scala Language Specification
says that this is part of the language.

Best regards
Andreas

Copyright © 2013 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland