Created
October 13, 2017 18:46
-
-
Save Rexagon/1de50b528057f06500b9b0b5adcfe839 to your computer and use it in GitHub Desktop.
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
DOMAINS | |
list=i* | |
i=integer | |
PREDICATES | |
nondeterm main() | |
nondeterm input_list(list) | |
nondeterm concatenate(list, list, list) | |
nondeterm concatenate(list, list, integer, list) | |
nondeterm print_list(list) | |
CLAUSES | |
main():- | |
input_list(L1), nl, | |
input_list(L2), nl, | |
concatenate(L1, L2, L3), | |
print_list(L3). | |
input_list([H|T]):- | |
write(">> "), | |
readint(H), | |
input_list(T). | |
input_list([]). | |
concatenate(L1, L2, L3):- | |
concatenate(L1,L2,0,L3). | |
concatenate([],[],_,[]). | |
concatenate(L1,[H2|T2],N,[H3|T3]):- | |
N mod 2 = 0, | |
NewN = N + 1, | |
H3 = H2, | |
concatenate(L1, T2, NewN, T3). | |
concatenate([H1|T1],L2,N,[H3|T3]):- | |
N mod 2 = 1, | |
NewN = N + 1, | |
H3 = H1, | |
concatenate(T1, L2, NewN, T3). | |
print_list([]). | |
print_list([H|T]):- | |
write(H, " "), | |
print_list(T). | |
GOAL | |
main(). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment