Prolog: append is failing inside loop -
i have following prolog code:
my_function(a):- my_function(a,[],1). my_function(a,list,num):- num_new num+1, generatel(o,s,l), write(l),nl, %append(l,list,list_new), ( num_new < 20 -> my_function(a,list_new,num_new) ). which working. loops through 19 times, calls generatel generates new term l print screen.
i want on each iteration append l list list create new list list_new passed through in recursive loop list such in next iteration list l again appended to.
i have attempted writing append statement commented out above. problem statement failing - believe because list_new not seen variable, rather pre-existing list, append testing whether list_new indeed l , list appended together, opposed creating new list list_new.
any ideas on how solve this? thanks!
if l term, can replace:
%append(l,list,list_new), with:
list_new=[l|list],
Comments
Post a Comment