Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有协议:
:- protocol(person). :- public([name/1, age/1]). :- end_protocol.
例如,我使用 制作了未知数量的对象,create_object/4我如何获得它们的数量?得到他们的名字不是问题current_object/1,但我需要一个整数!
create_object/4
current_object/1
假设只有对象(即没有类别)实现person协议,您可以使用例如计算它们的数量
person
count(N) :- findall(1, implements_protocol(_,person), L), list::length(L, N).
如果您有对象的层次结构,请将调用替换为implements_protocol /2。conforms_to_protocol/2您还可以count/1通过将协议作为参数传递来概括谓词。
implements_protocol /2
conforms_to_protocol/2
count/1