Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. % 50
  2. domains
  3. int = integer
  4. list=int*
  5.  
  6. predicates
  7. nondeterm enter(list)
  8. nondeterm run
  9. nondeterm do(char)
  10. nondeterm sublist(list,int,int,list)
  11.  
  12. clauses
  13. enter([H|T]):-
  14. write("Enter elements of the list or type 'end': "),
  15. readint(H),
  16. enter(T).
  17. enter([]):-!.
  18.  
  19. sublist([X|_],1,1,[X]).
  20. sublist([],_,_,[]).
  21. sublist([X|Xs],1,K,[X|Ys]):-
  22. K>1,
  23. K1 = K-1,
  24. sublist(Xs,1,K1,Ys).
  25. sublist([_|Xs],I,K,Ys):-
  26. I > 1,
  27. I1 = I-1,
  28. sublist(Xs,I1,K,Ys).
  29.  
  30. run:-
  31. write("*******ENTER*******"), nl,
  32. write("- 1 to START"),nl,
  33. write("- 0 to EXIT"),nl,
  34. write("***********************"),nl,
  35. write(">>"), readchar(X),
  36. write(X), nl, do(X), run.
  37.  
  38. do('1'):-
  39. enter(L),write("Your list is ",L),nl,
  40. write("Enter the constant "),readint(X),nl,
  41. write("Enter the length "),readint(Y),nl,
  42. sublist(L,X,Y,L1),nl,
  43. write("New list is ",L1),nl.
  44.  
  45. do('0'):-
  46. write("That's all"),exit.
  47.  
  48. do(_):-
  49. write("Bad value"), nl.
  50. goal
  51. run.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement