Różnice
Różnice między wybraną wersją a wersją aktualną.
|
|
— |
pl:prolog:pllib:list2term [2019/06/27 15:50] (aktualna) |
| ====== List2term ====== |
| {{tag>lists}} |
| ===== Description ===== |
| Constructing a term corresponding to a list. |
| |
| **Source**: The Art of Prolog |
| ===== Download ===== |
| Program source code: {{list2term.pl}} |
| ===== Listing ===== |
| <code prolog> |
| /* |
| univ(Term, List) :- |
| The functor of Term is the first element of the list List, |
| and its arguments are the rest of List's elements. |
| */ |
| |
| univ(Term, [F|Args]) :- |
| length(Args,N), functor(Term,F,N), args(Args,Term,1). |
| |
| args([Arg|Args],Term,N) :- |
| arg(N,Term,Arg), N1 is N+1, args(Args,Term,N1). |
| args([],Term,N). |
| /* |
| mylength(Xs,N) :- N is the mylength of the list Xs. |
| */ |
| mylength([X|Xs],N) :- mylength(Xs,N1), N is N1+1. |
| mylength([],0). |
| |
| % Program 9.5b Constructing a term corresponding to a list |
| |
| </code> |
| ===== Comments ===== |
| |