Reflection of defined predicates on un-instantiated classes? #182
-
Consider the following sample code and REPL statements :- object(thing,
instantiates(thing)).
:- end_object.
:- object(hat,
specializes(thing)
).
:- public( color/1).
color(red).
:- end_object.
:- object(hat1,
instantiates(hat)).
color(black).
:- end_object.
This all makes sense; in 3) color/1 doesn't exist because the class hat doesn't instantiate itself. I could make 3) work by adding instantiates(hat) to its definition, but at that point one might as well use a hierarchy of prototypes based on extends(). My question is: Is there a way of finding what predicate of color/1 is defined by hat, without instantiating hat? The context for this question is that I'm writing the type and cardinality verification code I asked about yesterday, and I ran into this question along the way. My verification code can create/destroy temp instantiation as needed, but it seems hacky, and I figure there might be something I'm missing about the Reflection API. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 14 replies
-
I assume you mean finding the clause for the |
Beta Was this translation helpful? Give feedback.
-
P.S. You can use:
for Logtalk syntax highlighting. |
Beta Was this translation helpful? Give feedback.
-
Btw, if you load the
You can load this (and other tools) automatically at startup by using a settings file. |
Beta Was this translation helpful? Give feedback.
-
P.S. Just pushed improved documentation for the https://logtalk3.readthedocs.io/en/latest/refman/methods/asserta_1.html |
Beta Was this translation helpful? Give feedback.
You also need to declare the
foo/1
predicate dynamic:After that change and after adding the following directive to the beginning of the file containing your code:
We get: