Guest User

Untitled

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. % Logtalk parametric entity parameters are _logical variables_
  2. % that are implicitly shared by all entity predicates.
  3. %
  4. % Parameters can be accessed using either the parameter/2 built-in
  5. % predicate or by using _parameter variables_. Here we use the
  6. % latter to decouple parameter access from parameter position.
  7. %
  8. % As ancestors should not force a specific parameter order on the
  9. % descendants (which would be a code smell), each prototype provides
  10. % a protected predicate (that can be overriden) for constructing a
  11. % new object identifier term from new values for its characteristic
  12. % parameters.
  13.  
  14.  
  15. :- object(point(_X_,_Y_)).
  16.  
  17. :- public(multiply/2).
  18. multiply(F, New) :-
  19. X is _X_ * F,
  20. Y is _Y_ * F,
  21. ::with_position(X, Y, New).
  22.  
  23. :- public(x/1).
  24. x(_X_).
  25.  
  26. :- public(with_x/2).
  27. with_x(X, New) :-
  28. ::with_position(X, _Y_, New).
  29.  
  30. :- public(y/1).
  31. y(_Y_).
  32.  
  33. :- public(with_y/2).
  34. with_y(Y, New) :-
  35. ::with_position(_X_, Y, New).
  36.  
  37. :- protected(with_position/3).
  38. with_position(X, Y, point(X, Y)).
  39.  
  40. :- end_object.
  41.  
  42.  
  43. :- object(colorpoint(_X_,_Y_,_C_),
  44. extends(point(_X_,_Y_))).
  45.  
  46. :- public(invert/1).
  47. invert(New) :-
  48. C is 255 - _C_,
  49. ::with_color(C, New).
  50.  
  51. :- public(color/1).
  52. color(_C_).
  53.  
  54. :- protected(with_color/2).
  55. with_color(C, colorpoint(_X_, _Y_, C)).
  56.  
  57. with_position(X, Y, colorpoint(X, Y, _C_)).
  58.  
  59. :- end_object.
  60.  
  61.  
  62. :- object(namedcolorpoint(_N_,_C_,_X_,_Y_),
  63. extends(colorpoint(_X_,_Y_,_C_))).
  64.  
  65. :- public(name/1).
  66. name(_N_).
  67.  
  68. :- protected(with_name/2).
  69. with_name(N, namedcolorpoint(N, _C_, _X_, _Y_)).
  70.  
  71. with_color(C, namedcolorpoint(_N_, C, _X_, _Y_)).
  72.  
  73. with_position(X, Y, namedcolorpoint(_N_, _C_, X, Y)).
  74.  
  75. :- end_object.
Add Comment
Please, Sign In to add comment