Traits

Traits are defined using TRAITDEF(...):

import treehugger.forest._, definitions._, treehuggerDSL._

val tree = TRAITDEF("Philosophical") := BLOCK(
  PROC("philosophize") := BLOCK(
    LIT(0)
  )
)

val tree2 = (CLASSDEF("Animal"): Tree)

val tree3 = (TRAITDEF("HasLegs"): Tree)

val tree4 = (CLASSDEF("Frog")
    withParents("Animal", "HasLegs", "Philosophical") := BLOCK(
  DEF(Any_toString) withFlags(Flags.OVERRIDE) := LIT("green")
))

These print as:

treeToString(tree)
// res0: String = """trait Philosophical {
//   def philosophize {
//     0
//   }
// }"""

treeToString(tree2)
// res1: String = "class Animal"

treeToString(tree3)
// res2: String = "trait HasLegs"

treeToString(tree4)
// res3: String = """class Frog extends Animal with HasLegs with Philosophical {
//   override def toString = "green"
// }"""