function

let's make a function.

in this language, you can use the "double" function to double a number. write "double" and then write a number to double the number.

TRANSLATED:



matching the function is easy. make a list.

const listTerm = new ListTerm([
	new StringTerm("double"),
	new MaybeTerm(new GapTerm()),
	new NumberTerm(),
])

to get it to ACTUALLY do something, give it a custom emit function with "with".

const functionTerm = new WithTerm(listTerm, {
	emit(text) {
		const [, , number] = this.digest(text)
		return number * 2
	},
})

then use it.

function translate(text) {
	return functionTerm.translate(text)
}

back to the dream