Advertisement
Guest User

Untitled

a guest
Apr 1st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.25 KB | None | 0 0
  1. % This buffer is for notes you don't want to save.
  2. % If you want to create a file, visit that file with C-x C-f,
  3. % then enter the text in that file's own buffer.
  4.  
  5. %Problem1
  6. :-op(300, xfx, plays).
  7. %:-op(200, xfy, and).
  8.  
  9. :-op(500,xfx, was).
  10. :-op(600, xfx, of).
  11. :-op(400, fx, the).
  12.  
  13. %plays(jimmy, and(football, and(basketball, tennis))).
  14.  
  15. john was the secretary of the department.
  16. %was(john, of(the(secretary), the(department))).
  17. %
  18. %
  19. %Problem 2
  20. :-op(40,fx,deleting).
  21. :-op(20,xfx, gives).
  22. :-op(30,xfx, from).
  23.  
  24. deleting _ from [] gives [].
  25. deleting Item from [Item|Tail] gives Result :-
  26.     deleting Item from Tail gives Result.
  27. deleting Item from [Head|Tail] gives [Head|Result]:-
  28.     Item \= Head,
  29.     deleting Item from Tail gives Result.
  30.  
  31. :-op(500, fx, concat).
  32. :-op(15, yfx, and).
  33.  
  34. concat List1 and List2 gives Result :-
  35.     is_list(List1),
  36.     is_list(List2),
  37.     append(List1, List2, Result).
  38. concat Expr and List gives Result :-
  39.     concat Expr gives L1,
  40.     append(L1, List, Result).
  41. %Problem 3
  42.  
  43. sq(N) :-
  44.     number(N),
  45.     S is N*N,
  46.     writef('%d \n',[S]).
  47.  
  48.  
  49. squares :-
  50.     writef('Give number: '),
  51.     read(Term),
  52.     Term \= stop,
  53.     sq(Term),
  54.     squares.
  55.  
  56. %Problem 4
  57. %
  58.  
  59. writelist([]) :- !.
  60. writelist([H|T]) :-
  61.     write(H),
  62.     write(' '),
  63.     writelist(T).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement