Różnice
Różnice między wybraną wersją a wersją aktualną.
|
|
— |
pl:prolog:pllib:flatten_4 [2019/06/27 15:50] (aktualna) |
| ====== Flatten 4 ====== |
| {{tag>lists operators}} |
| ===== Description ===== |
| Flattening a list of lists using difference-lists |
| |
| **Source**: The Art of Prolog |
| ===== Download ===== |
| Program source code: {{flatten_4.pl}} |
| ===== Listing ===== |
| <code prolog> |
| /* |
| flatten(Xs,Ys) :- |
| Ys is a flattened list containing the elements in Xs. |
| */ |
| :- op(40,xfx,\). |
| |
| flatten(Xs,Ys) :- flatten_dl(Xs,Ys\[]). |
| |
| flatten_dl([X|Xs],Ys\Zs) :- |
| flatten_dl(X,Ys\Ys1), flatten_dl(Xs,Ys1\Zs). |
| flatten_dl(X,[X|Xs]\Xs) :- |
| constant(X), X \== []. |
| flatten_dl([],Xs\Xs). |
| |
| % Program 15.2 : Flattening a list of lists using difference-lists |
| </code> |
| ===== Comments ===== |
| |