Różnice
Różnice między wybraną wersją a wersją aktualną.
|
|
— |
pl:prolog:pllib:findall [2019/06/27 15:50] (aktualna) |
| ====== Findall ====== |
| {{tag>predicates}} |
| ===== Description ===== |
| An implementation of the findall relation. |
| |
| |
| **Source**: PROLOG programming for artificial intelligence, 3rd Edition, Harlow, 2001, ISBN 0-201-40375-7. |
| |
| ===== Download ===== |
| Program source code: {{findall.pl}} |
| ===== Listing ===== |
| <code prolog> |
| % Figure 7.4 An implementation of the findall relation. |
| |
| |
| |
| |
| |
| findall( X, Goal, Xlist) :- |
| |
| call( Goal), % Find a solution |
| |
| assertz( queue(X) ), % Assert it |
| |
| fail; % Try to find more solutions |
| |
| assertz( queue(bottom) ), % Mark end of solutions |
| |
| collect( Xlist). % Collect the solutions |
| |
| |
| |
| collect( L) :- |
| |
| retract( queue(X) ), !, % Retract next solution |
| |
| ( X == bottom, !, L = [] % End of solutions? |
| |
| ; |
| |
| L = [X | Rest], collect( Rest) ). % Otherwise collect th |
| e rest |
| |
| </code> |
| ===== Comments ===== |
| RTERR: No permission to modify static procedure. |