setlog中setof的源代码是什么?

最佳答案

?- listing(setof).
:- meta_predicate setof(?,0,-).

setof(A, B, F) :-
    free_variable_set(A, B, D, C),
    (   C==v
    ->  findall(A, D, E),
        E\==[],
        sort(E, F)
    ;   findall(C-A, D, E),
        (   ground(E)
        ->  sort(E, G),
        pick(G, C, F)
        ;   bind_bagof_keys(E, _),
        sort(E, G),
        pick(G, C, H),
        sort(H, F)
        )
    ).

true.

09-05 14:48