Created
February 28, 2018 22:57
-
-
Save lexbailey/568e2500b2be42a88cfe566d0e36e1d0 to your computer and use it in GitHub Desktop.
How NOT to implement sum in prolog
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
| :- dynamic total/1. | |
| total(0). | |
| sum([], S) :- | |
| total(S), | |
| retract(total(S)), | |
| assert(total(0)). | |
| sum([H|T], S) :- | |
| total(A), | |
| retract(total(A)), | |
| N is A + H, | |
| assert(total(N)), | |
| sum(T, S). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.