Two different ways to express List in Prolog -


what's difference between these 2 clauses:

l=[x,h|y].  append(x,[h|y],l). 

it's 1 clause in code, first 1 not work, second 1 works, don't know difference.

the expression [x,h|y] denotes list first term value of x, second term value of h, , tail value of y. if x = 1, h = 2, , y = [3,4,5], value [1,2,3,4,5]. if x = [1,2,3], h = [4,5,6], , y = [7,8,9], value [[1,2,3], [4,5,6], 7, 8, 9]. expression l=[x,h|y] binds value of list l.

the predicate append(x,[h|y],l), on other hand, appends list first term h , tail y list x, , binds result l. if x = 1, h = 2, , y = [3,4,5], result error, since x not list. if x = [1,2,3], h = [4,5,6], , y = [7,8,9], result bind l value [1,2,3, [4,5,6], 7, 8, 9].


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -