% Common shared database loaded by every deployment node. % Holds the family relations used in the tutorial's local and distributed % Prolog sections. ancestor_descendant(X, Y) :- parent_child(X, Y). ancestor_descendant(X, Z) :- parent_child(X, Y), ancestor_descendant(Y, Z). parent_child(X, Y) :- mother_child(X, Y). parent_child(X, Y) :- father_child(X, Y). mother_child(trude, sally). father_child(tom, sally). father_child(tom, erica). father_child(mike, tom). list_price(widget, 100). list_price(gadget, 250). list_price(gizmo, 400). price(Item, Price) :- list_price(Item, Price). % Shared database loaded by all ACTOR-profile deployment nodes (n3, n4). % Holds the actor predicates that the tutorial expects to find on either % public actor node, plus the public service directory. service(counter, meta(actor, protocol(count_v1))). service(pubsub_service, meta(actor, protocol(pubsub_v1))). echo_actor :- receive({ echo(From, Msg) -> From ! echo(Msg), echo_actor }). count_actor(Count0) :- receive({ count(From) -> Count is Count0 + 1, From ! count(Count), count_actor(Count) ; stop -> true }). % Native ping-pong benchmark. The worker predicates live in this shared % database, so the spawned actors can call them directly: no src_* source % transfer or private source installation is part of the measurement. ping_pong :- ping_pong(1000). ping_pong(RoundTrips) :- must_be(nonneg, RoundTrips), self(MasterPid), spawn(pong(MasterPid), PongPid), spawn(ping(RoundTrips, PongPid)), receive({finished -> true}). ping_pong_benchmark(RoundTrips, Microseconds) :- get_time(T0), ping_pong(RoundTrips), get_time(T1), Microseconds is round((T1-T0) * 1_000_000). ping(0, PongPid) :- PongPid ! finished. ping(N, PongPid) :- self(Self), PongPid ! ping(Self), receive({pong -> true}), N1 is N - 1, ping(N1, PongPid). pong(MasterPid) :- receive({ finished -> MasterPid ! finished ; ping(PingPid) -> PingPid ! pong, pong(MasterPid) }). authorized(alice). owns(alice, printer2). online(printer2). % n3 is the public actor-demo node. % The shared actor predicates are in shared_db_actor_common.pl. This overlay % holds only n3-specific predicates: the deployment marker and the % mortal/human chain that the tutorial's distributed proof tree pulls % through to n4. :- dynamic mortal/1, human/1. mortal(X) :- human(X). human(socrates). human(X) :- rpc('https://n4.elfenbenstornet.se', human(X)). % Shared database used by example 13 shared-database.xml. shared_fact(n3_shared_db). % The statechart datamodel defines local_label/1 too. Its local definition % shadows this shared one while the chart is running. local_label(n3_shared_db). shared_transition_enabled. % Fixed, owner-installed inference capability. No network primitive is % exposed to public source; answers return in the caller's own execution. model_answer(Prompt, Result) :- model_service:model_answer(Prompt, Result). % Bounded multi-turn conversation; history remains owned by the caller. model_chat(Messages, Result) :- model_service:model_chat(Messages, Result).