title: Nested pattern matching in Scala
body: <p>I'm new to Scala and I'm trying to understand how pattern matching works. So I wrote this basic code, which returned the expected result:</p>
  
  <pre><code>def test(choice: Int): String = choice match {
    case x if x &gt; 0 &amp;&amp; x%2 == 0 =&gt; "positive even number"
    case x if x &gt; 0 &amp;&amp; x%2 != 0 =&gt; "positive odd number"
    case 0 =&gt; "null"
    case x if x &lt; 0 &amp;&amp; x%2 == 0 =&gt; "negative even number" 
    case x if x &lt; 0 &amp;&amp; x%2 != 0 =&gt; "negative odd number"
  }
  </code></pre>
  
  <p>Now I'm trying to do something a little more elaborate:</p>
  
  <pre><code>def test(choice: Int): String = choice match {
  
    case x if x%2 == 0 =&gt; x match {
      case y if y &gt; 0 =&gt; "even and positive number" 
      case y if y &lt; 0 =&gt; "even and negative number"
      }
    case 0 =&gt; "null"
    case x if x%2 != 0 =&gt; x match {
      case y if y &gt; 0 =&gt; "odd and positive number" 
      case y if y &lt; 0 =&gt; "odd and negative number"
      }
  }
  </code></pre>
  
  <p>But it failed. Here's the error message on the console:</p>
  
  <pre><code>scala&gt; def test(choice: Int): String = choice match {
       |
       |   case x if x%2 == 0 =&gt; x match {
       | case y if y &gt; 0 =&gt; "even and positive number"
       | Display all 600 possibilities? (y or n)
       [...]
  
       |  if y &lt; 0 =&gt; "even and negative number"
  &lt;console&gt;:5: error: '(' expected but identifier found.
   if y &lt; 0 =&gt; "even and negative number"
      ^
  
      [...]
  </code></pre>
  
  <p>Can somebody tell me what I'm doing wrong and give me some details about what I misunderstand about Scala in general and the <code>match</code> method in particular.</p>