Created
September 13, 2011 15:38
-
-
Save ejamesc/1214138 to your computer and use it in GitHub Desktop.
Operand matching
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
/* End cases, where str is atom or number */ | |
count(Str, Op, 0) :- atom(Str). | |
count(Str, Op, 0) :- number(Str). | |
/* Program */ | |
count(Str, Op, R) :- Str =..[A,B,C], | |
test(A, Op, R1), | |
count(B, Op, R2), | |
count(C, Op, R3), | |
R is R1 + R2 + R3. | |
count(Str, Op, R) :- Str =..[A,B], | |
count(A, Op, R1), | |
count(B, Op, R2), | |
R is R1 + R2. | |
/* Test returns 1 if operand matches; else 0 */ | |
test(Str, Op, R) :- Str = Op, atom(Str), R is 1; R is 0. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment