The ::/2
message sending control construct indeed requires a bound first argument at call time. But you can enumerate existing objects using the current_object/1
built-in predicate:
| ?- current_object(Person), Person::name(john).
...
However, this solution may also result in errors as we will be enumerating all objects by backtracking and not all of them will understand a name/1
message. A better solution is thus to only enumerate objects that understand the name/1
message. Assuming that all objects representing a person implement (directly or through inheritance) a person_protocol
, we can use the conforms_to_protocol/2
built-in predicate:
| ?- conforms_to_protocol(Person, person_protocol),
Person::name(john).
...
See https://logtalk.org/manuals/refman/predicates/conforms_to_protocol_2_3.html for details.