emit

it's good to make your language emit something.

this language bites of "ping" or "pong" and emits the opposite.

TRANSLATED:



create the ping term with "with".

const pingTerm = new WithTerm(new StringTerm("ping"), {
	emit(text) {
		return "pong"
	}
})

create the pong term with "with".

const pongTerm = new WithTerm(new StringTerm("pong"), {
	emit(text) {
		return "ping"
	}
})

create the ping pong term with "or".

const pingPongTerm = new OrTerm([pingTerm, pongTerm])

use it.

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

back to the dream