Skip to content

Instantly share code, notes, and snippets.

@lexbailey
Created February 28, 2018 22:57
Show Gist options
  • Select an option

  • Save lexbailey/568e2500b2be42a88cfe566d0e36e1d0 to your computer and use it in GitHub Desktop.

Select an option

Save lexbailey/568e2500b2be42a88cfe566d0e36e1d0 to your computer and use it in GitHub Desktop.
How NOT to implement sum in prolog
:- 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).
@ddm999

ddm999 commented Mar 3, 2018

Copy link
Copy Markdown
% ... 1,000,000 ............ 10,000,000 years later
% 
%       >> 42 << (last release gives the question)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment