List2term

Description

Constructing a term corresponding to a list.

Source: The Art of Prolog

Download

Program source code: list2term.pl

Listing

/*
   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

Comments

pl/prolog/pllib/list2term.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0