Calling the Interpreter

call


Dynamic Predicates

asserta, assertz, retract Prolog is used by relational database developers, using these predicates to store and remove data. The relation name is used as the predicate symbol, and each field of a tuple is stored as an argument of a fact. The relational select operation is immediately available, with unifiability as the selection criteria, via a query. By allowing rules in the relational database a deductive database is formed. These predicates should never be used to store temporary results - use another variable.

clause(Head,Tail)


Collectors

These are used for collecting up alternative solutions, as would be provided by asking for more at the prompt.

findall(Variable,Query,ListOfSolutionsForTheVariable)

bagof(Variable,Query,ListOfSolutionsForTheVariable)

setof(Variable,Query,ListOfSolutionsForTheVariable)

Tutorial

  1. Write your own version of consult and reconsult.
  2. Here's a dirty implementation of findall that does not work for nested findalls.
    findall(Variable,Goal,_):-
        Goal, 
        assertz(found(Variable)),
        fail.
    
    findall(_,_,List):-
        collect_found(List).
        
    collect_found([FirstFound|RestFound]):-
        retract(found(FirstFound)),
        !,
        collect_found(RestFound).
    
    collect_found([]).
         
    Write a version of findall that works for nested invocations.