title: In this Scala case class, why doesn't List.mkString work with a previous parameter's value?
body: <p>I am attempting to provide a reasonable default should the user not provide the name parameter. Doing the following in the Scala Worksheet in the Eclipse IDE is generating a compiler error:  </p>
  
  <pre><code>case class Type(id: Int, name: String, description: String = "")
  case class Definition(id: Int, types: List[Type], separator: String = ";", name: String = types.mkString(separator))
  </code></pre>
  
  <p>The error is "not found: value separator" indicated on the identifier "separator" inside the mkString method call for List. Since this is a case class and the previous parameters have been already defined, why am I not able to use "separator" in defining the default value for name. And it turns out I cannot even use "types" in defining the default value for "name", either.</p>
  
  <p>I tried to work around this, but I don't see how without turning name into a var, which isn't something I want to do. Any guidance or understanding on this is appreciated.</p>
  
  <p>UPDATE:
  Okay, the way I found to get around this was to use the companion object to forward to the constructor:</p>
  
  <pre><code>  case class Type(id: Int, name: String, description: String = "")
    object Definition {
      def create(id: Int, types: List[Type], separator: String = ";", name: String = "") =
        Definition(id, types, separator, if (name != "") name else types.map(_.name).mkString(separator))
    }
    case class Definition(id: Int, types: List[Type], separator: String = ";", name: String) {
      require(!separator.isEmpty, "separator must not be empty")
      require(!name.isEmpty, "name must not be empty")
    }
  </code></pre>
  
  <p>This sure is quite a bit of Java-like boilerplate compared to what I originally tried to do. Are there other/better ways to do this?</p>