Skip to content

Instantly share code, notes, and snippets.

@Leonidas-from-XIV
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save Leonidas-from-XIV/a4043bd8da6e03477b3a to your computer and use it in GitHub Desktop.

Select an option

Save Leonidas-from-XIV/a4043bd8da6e03477b3a to your computer and use it in GitHub Desktop.
Virtual Machines demo program in Proll (load into SWI with ['vm.pl'].)
% SWI can do multiplication otherwise, but Proll does not, so define a mul predicate
mul(0, _, 0).
mul(_, 0, 0).
mul(1, Y, Y).
mul(X, 1, X).
mul(X, Y, Z) :- plus(Xpred, 1, X), mul(Xpred, Y, Zpred), plus(Zpred, Y, Z), !.
% our function, call f(8, 5, Z).
f(X, Y, Z) :- mul(X, Y, Zsucc), plus(Zsucc, 2, Z).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment