squares(0,[]).
squares(N,[N1|T]) :- N1 is N*N, N2 is N-1, squares(N2,T).
llength([],0).
llength([_|T],L) :- 
 llength(T,L1), L is L1+1.
contains(_,[]) :- fail.
contains(X,[X|_]).
contains(X,[_|T]) :- contains(X,T).
find(F,[[F,S]|_],S).
find(F,[_|T],S) :- find(F,T,S).
ordered([]).	
ordered([A]).
ordered([A|[B|T]]) :- A<B,ordered([B|T]).
insert(V,[],[V]).
insert(V,[H|T],[V|[H|T]]) :- V<H.
insert(V,[H|T],[H|T1]) :- insert(V,T,T1).
ssort([],[]).
ssort([H|T],L) :- ssort(T,T1),insert(H,T1,L).
wordsToDB([]).
wordsToDB([[N,W]|T]) :- assert(word(N,W)),wordsToDB(T).
age(al,18).
age(bea,19).
age(cam,20).
age(deb,21).
people(P) :- assert(ages([])),getAges(P).
getAges(P) :- age(N,A),getAge(N,A).
getAges(P) :- retract(ages(P)).
getAge(N,A) :- retract(ages(P)),assert(ages([[N,A]|P])),!,fail.
copyTerms :- read(X),copyTerms1(X).
copyTerms1(end_of_file).
copyTerms1(X) :- write(X),nl,read(Y),copyTerms1(Y).
getTerms(L) :- read(X),getTerms1(X,L).
getTerms1(end_of_file,[]).
getTerms1(X,[X|L]) :- read(Y),getTerms1(Y,L).
getChars(L) :- get_char(X),getChars1(X,L).
getChars1(end_of_file,[]).
getChars1(X,[X|L]) :- get_char(Y),getChars1(Y,L).
copyChars :- get_char(X),copyChars1(X).
copyChars1(end_of_file).
copyChars1(X) :- put_char(X),get_char(Y),copyChars1(Y).
copyFile(X,Y) :-
 open(X,read,F1),set_input(F1),
 open(Y,write,F2),set_output(F2),
 copyChars,
 close(F1),close(F2).
