Function Applications

There are two ways to write function applications. The first way is calling APPLY(arg, ...) on a symbol or a tree. Here, arg denotes a Tree:

import treehugger.forest._, definitions._, treehuggerDSL._
val tree = Predef_println APPLY LIT("Hello, world!")
treeToString(tree)
// res0: String = "println(\"Hello, world!\")"
val tree2 = (REF("x") DOT "y") APPLY (LIT(0), LIT(1))
treeToString(tree2)
// res1: String = "x.y(0, 1)"

Function application on selections

The second way is to apply arg, ... on intermediate structure returned by DOT(sym|"y"):

val tree3 = (REF("x") DOT "y")(LIT(0), LIT(1))
treeToString(tree3)
// res2: String = "x.y(0, 1)"

Sequence arguments

To pass sequence into a vararg parameter, use SEQARG(arg):

val tree4 = THIS APPLY (SEQARG(REF("list")))
treeToString(tree4)
// res3: String = "this((list: _*))"

Named arguments

To pass named arguments into a function, specify the parameter using REF(sym|"x") as follows:

val tree5 = REF("put") APPLY (REF("x") := LIT(0))
treeToString(tree5)
// res4: String = "put(x = 0)"

Partially applied functions

Partially applied functions are written by calling APPLY with PARTIALLY:

val tree6 = REF("put") APPLY PARTIALLY
treeToString(tree6)
// res5: String = "put _"

Note this is different from APPLYing WILDCARD since PARTIALLY applies to the entire parameter list.