title: scala: define default parameters in a function (val) vs using a method (def)
body: <p>I have the following method:</p>
  
  <pre><code>scala&gt; def method_with_default(x: String = "default") = {x + "!"}
  method_with_default: (x: String)java.lang.String
  
  scala&gt; method_with_default()
  res5: java.lang.String = default!
  
  scala&gt; method_with_default("value")
  res6: java.lang.String = value!
  </code></pre>
  
  <p>I'm trying to achieve the same with a val, but I get a syntax error, like this:</p>
  
  <p>(with no default value, this one compiles ok)</p>
  
  <pre><code>scala&gt; val function_with_default = (x: String) =&gt; {x + "!"}
  function_with_default: String =&gt; java.lang.String = &lt;function1&gt;
  </code></pre>
  
  <p>(but I couldn't get this one to compile...)</p>
  
  <pre><code>scala&gt; val function_with_default = (x: String = "default") =&gt; {x + "!"}
  &lt;console&gt;:1: error: ')' expected but '=' found.
         val function_with_default = (x: String = "default") =&gt; {x + "!"}
                                                ^
  </code></pre>
  
  <p>any idea?</p>