Skip to content

Instantly share code, notes, and snippets.

@Rexagon
Created October 13, 2017 17:25
Show Gist options
  • Save Rexagon/c6449d43935c2781e28c65c100973640 to your computer and use it in GitHub Desktop.
Save Rexagon/c6449d43935c2781e28c65c100973640 to your computer and use it in GitHub Desktop.
DOMAINS
list=i*
i=integer
PREDICATES
nondeterm main()
nondeterm input_list(list)
nondeterm make_positive(list, list)
nondeterm print_list(list)
CLAUSES
main():-
input_list(L),
make_positive(L, NewL),
print_list(NewL).
input_list([H|T]):-
write(">> "),
readint(H),
input_list(T).
input_list([]).
make_positive([],[]).
make_positive([H|T1], [H|T2]):-
H >= 0,
make_positive(T1, T2).
make_positive([H1|T1], [H2|T2]):-
H1 < 0,
H2 = -H1,
make_positive(T1, 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