Sunday, June 3, 2012

how to append two list in visual prolog programming


Visual Prolog Program to append two list.


Here the two list are taken by the predicate “append” and returns the appended list. To append two list a list is broken continuously until the last empty list is encountered and finally the other list is appended or joined at the end of first recursively. The code to append is given as follows:

DOMAINS
int_list=Integer *

PREDICATES
append(int_list,int_list,int_list)
CLAUSES

append([],X,Z):-
Z=X.
append([H|T],X,Y):-
append(T,X,Z),Y=[H|Z].
GOAL
append([1,2,3,4,5],[6,7,8,9],X).

1 comment: