Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % 50
- domains
- int = integer
- list=int*
- predicates
- nondeterm enter(list)
- nondeterm run
- nondeterm do(char)
- nondeterm sublist(list,int,int,list)
- clauses
- enter([H|T]):-
- write("Enter elements of the list or type 'end': "),
- readint(H),
- enter(T).
- enter([]):-!.
- sublist([X|_],1,1,[X]).
- sublist([],_,_,[]).
- sublist([X|Xs],1,K,[X|Ys]):-
- K>1,
- K1 = K-1,
- sublist(Xs,1,K1,Ys).
- sublist([_|Xs],I,K,Ys):-
- I > 1,
- I1 = I-1,
- sublist(Xs,I1,K,Ys).
- run:-
- write("*******ENTER*******"), nl,
- write("- 1 to START"),nl,
- write("- 0 to EXIT"),nl,
- write("***********************"),nl,
- write(">>"), readchar(X),
- write(X), nl, do(X), run.
- do('1'):-
- enter(L),write("Your list is ",L),nl,
- write("Enter the constant "),readint(X),nl,
- write("Enter the length "),readint(Y),nl,
- sublist(L,X,Y,L1),nl,
- write("New list is ",L1),nl.
- do('0'):-
- write("That's all"),exit.
- do(_):-
- write("Bad value"), nl.
- goal
- run.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement