Created
March 30, 2020 20:36
-
-
Save LamentConfiguration/bbdd8f2c51c77aa481546e8682986e3e to your computer and use it in GitHub Desktop.
predicate naming
This file contains 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
basicpart(rim). | |
basicpart(spoke). | |
basicpart(rearframe). | |
basicpart(handles). | |
basicpart(gears). | |
basicpart(bolt). | |
basicpart(nut). | |
basicpart(fork). | |
assembly(bike, [wheel, wheel, frame]). | |
assembly(wheel, [spoke, rim, hub]). | |
assembly(frame, [rearframe, frontframe]). | |
assembly(frontframe, [fork, handles]). | |
assembly(hub, [gears, axle]). | |
assembly(axle, [bolt, nut]). | |
% basic predicate | |
partsof(X,P):-partsacc(X,[],P). | |
% helper predicate boundary case | |
partsacc(X,A,[X|A]):-basicpart(X). | |
% helper predicate | |
partsacc(X,A,P):- | |
assembly(X, Subparts), | |
partsacclist(Subparts,A,P). | |
% worker predicate base case | |
partsacclist([],A,A). | |
% worker predicate recursive case | |
partsacclist([P|Tail], A, Total):- | |
partsacc(P,A,Hp), | |
partsacclist(Tail, Hp, Total). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment