Created
October 13, 2017 17:31
-
-
Save Rexagon/a94e9da9a25f4ae7eccf519d5e8fbbc7 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 change_last(list, integer, list) | |
nondeterm print_list(list) | |
CLAUSES | |
main():- | |
input_list(L), | |
write("last element >> "), readint(X), | |
change_last(L, X, NewL), | |
print_list(NewL). | |
input_list([H|T]):- | |
write(">> "), | |
readint(H), | |
input_list(T). | |
input_list([]). | |
change_last([], _, []). | |
change_last([H|[]], X, [X|[]]). | |
change_last([H|T1], X, [H|T2]):- | |
change_last(T1,X,T2). | |
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