SWI-Prolog / packages-pengines

Pengines: Prolog engines
11 stars 13 forks source link

Likely bug in pengine_property/2 #53

Closed dtonhofer closed 3 years ago

dtonhofer commented 3 years ago

In pengines.pl on line 876:

/** pengine_property(?Pengine, ?Property) is nondet.

True when Property is a property of   the  given Pengine. Enumerates all
pengines  that  are  known  to  the   calling  Prolog  process.  Defined
properties are:

  * self(ID)
    Identifier of the pengine.  This is the same as the first argument,
    and can be used to enumerate all known pengines.
  * alias(Name)
    Name is the alias name of the pengine, as provided through the
    `alias` option when creating the pengine.
  * thread(Thread)
    If the pengine is a local pengine, Thread is the Prolog thread
    identifier of the pengine.
  * remote(Server)
    If the pengine is remote, the URL of the server.
  * application(Application)
    Pengine runs the given application
  * module(Module)
    Temporary module used for running the Pengine.
  * destroy(Destroy)
    Destroy is =true= if the pengines is destroyed automatically
    after completing the query.
  * parent(Queue)
    Message queue to which the (local) pengine reports.
  * source(?SourceID, ?Source)
    Source is the source code with the given SourceID. May be present if
    the setting `debug_info` is present.
  * detached(?Time)
    Pengine was detached at Time.
*/

pengine_property(Id, Prop) :-
    nonvar(Id), nonvar(Prop),
    pengine_property2(Id, Prop),
    !.
pengine_property(Id, Prop) :-
    pengine_property2(Prop, Id).

pengine_property2(self(Id), Id) :-
    current_pengine(Id, _Parent, _Thread, _URL, _Application, _Destroy).
pengine_property2(module(Id), Id) :-
    current_pengine(Id, _Parent, _Thread, _URL, _Application, _Destroy).
pengine_property2(alias(Alias), Id) :-
...

The first clause for pengine_property(Id, Prop) evidently is mean to succeed/fail if both arguments are instantiated. However the call to the pengine_property2(Id, Prop) has the arguments in the wrong order. Should be

pengine_property(Id, Prop) :-
    nonvar(Id), nonvar(Prop),
    pengine_property2(Prop, Id),
    !.
JanWielemaker commented 3 years ago

Good catch. Fixed with 5c096a3ea911b8149f09bb633832d484a5f5850e