Skip to content

Instantly share code, notes, and snippets.

@j14159
Created March 7, 2014 19:59
Show Gist options
  • Save j14159/9418780 to your computer and use it in GitHub Desktop.
Save j14159/9418780 to your computer and use it in GitHub Desktop.
package definterp
import org.scalatest._
class AdditionProgram extends FlatSpec with Matchers {
val addition =
Lambda("x",
Lambda("y", LetRec("add-until",
Lambda("xx",
Lambda("added",
Cond(
Appl(Appl(Eq, DVar("added")), DVar("y")),
DVar("xx"),
Appl(Appl(DVar("add-until"), Appl(Succ, DVar("xx"))), Appl(Succ, DVar("added"))))
)),
Appl(Appl(DVar("add-until"), DVar("x")), DInteger(0)))))
val program = List(
Appl(Appl(addition, DInteger(2)), DInteger(3))
)
"A curried addition function only using eq and succ" should "return the correct result" in {
Interpreter.interpret(program) should be (DInteger(5))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment