Skip to content

Instantly share code, notes, and snippets.

@Rexagon
Created October 13, 2017 17:31
Show Gist options
  • Save Rexagon/a94e9da9a25f4ae7eccf519d5e8fbbc7 to your computer and use it in GitHub Desktop.
Save Rexagon/a94e9da9a25f4ae7eccf519d5e8fbbc7 to your computer and use it in GitHub Desktop.
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