The event creation requires non-logical copying of the goal. As a result, if the goal contains variables, they lose their identity and are replaced with fresh ones.
The intended use of such events are for localised event handling or when it is necessary to pass ground parameters to the event goal, i.e. when the use of a global event handler is unnecessary or does not suffice.
It should be noted that the event handle is the only way to uniquely identify a given event. E.g. if an event has been scheduled as an after-event (using event_after/3 or events_after/2), it can only be cancelled by invoking cancel_after_event/2 with the correct handle.
The following options are recognised:
% Create and raise a single event ?- event_create(writeln('Goodbye cruel world!'), [], Event), writeln('Hello world!'), event(Event). Hello world! Goodbye cruel world! Event = $&(event,"371bsj") Yes (0.00s cpu) % Raise events via a timer ?- event_create(writeln('e1'), [], E1Event), event_create(writeln('e2'), [], E2Event), events_after([E1Event-every(0.2), E2Event-0.5]), repeat, fail. e1 e1 e2 e1 e1 ^C interruption: type a, b, c, e, or h for help : ? e1 abort Aborting execution ... % By default, event handlers are allowed to interrupt each other, % which can make it seem that they are handled in reverse order: ?- event_create(writeln('e1'), [], E1Event), event_create(writeln('e2'), [], E2Event), event([E1Event,E2Event]). % raise both events together e2 e1 E1Event = $&(event,"371bqb") E2Event = $&(event,"371bqz") Yes (0.00s cpu) % By default, event handlers are allowed to interrupt each other, % which can make it seem that they are handled in reverse order: ?- event_create((writeln('e1'),events_nodefer), [defers], E1Event), event_create((writeln('e2'),events_nodefer), [defers], E2Event), event([E1Event,E2Event]). % raise both events together e1 e2 E1Event = $&(event,"371bqb") E2Event = $&(event,"371bqz") Yes (0.00s cpu)