Last active
August 29, 2015 14:03
-
-
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'].)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % 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