Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Logtalk parametric entity parameters are _logical variables_
- % that are implicitly shared by all entity predicates.
- %
- % Parameters can be accessed using either the parameter/2 built-in
- % predicate or by using _parameter variables_. Here we use the
- % latter to decouple parameter access from parameter position.
- %
- % As ancestors should not force a specific parameter order on the
- % descendants (which would be a code smell), each prototype provides
- % a protected predicate (that can be overriden) for constructing a
- % new object identifier term from new values for its characteristic
- % parameters.
- :- object(point(_X_,_Y_)).
- :- public(multiply/2).
- multiply(F, New) :-
- X is _X_ * F,
- Y is _Y_ * F,
- ::with_position(X, Y, New).
- :- public(x/1).
- x(_X_).
- :- public(with_x/2).
- with_x(X, New) :-
- ::with_position(X, _Y_, New).
- :- public(y/1).
- y(_Y_).
- :- public(with_y/2).
- with_y(Y, New) :-
- ::with_position(_X_, Y, New).
- :- protected(with_position/3).
- with_position(X, Y, point(X, Y)).
- :- end_object.
- :- object(colorpoint(_X_,_Y_,_C_),
- extends(point(_X_,_Y_))).
- :- public(invert/1).
- invert(New) :-
- C is 255 - _C_,
- ::with_color(C, New).
- :- public(color/1).
- color(_C_).
- :- protected(with_color/2).
- with_color(C, colorpoint(_X_, _Y_, C)).
- with_position(X, Y, colorpoint(X, Y, _C_)).
- :- end_object.
- :- object(namedcolorpoint(_N_,_C_,_X_,_Y_),
- extends(colorpoint(_X_,_Y_,_C_))).
- :- public(name/1).
- name(_N_).
- :- protected(with_name/2).
- with_name(N, namedcolorpoint(N, _C_, _X_, _Y_)).
- with_color(C, namedcolorpoint(_N_, C, _X_, _Y_)).
- with_position(X, Y, namedcolorpoint(_N_, _C_, X, Y)).
- :- end_object.
Add Comment
Please, Sign In to add comment