i m doing associative list in prolog i seen this topic but i dont understand the code.
For checking list is associative isn't enough do this:
lists([_X, _Y]).
lists([[H|_T]|L],[H|T]):- lists(L,T).
Because for first /1 i check if have element in this way [a,3] and /2 take list of list [[a,4],[a,3]] in this way. so first pass call list/2 on [a,3], and check true for base case, and after call [a,4] and call true for base case too.
I wrong something, but i don't see,
Anyone can clarify me?
OP's update of 2019-01-01 10:40:47Z:
I try to resolve in this way:
islist([_X,_Y]).
islist([_X|T]):- islist(T).
In this case accept just input in this way
[[k,v],[k,v],[k,v]]
but accept all input like this:
- [a]
- [k,v,v,v]
- [[k,v],[k,v],[k,v,v]]
So my problem remains.