Prolog: list as tail of a list

5afb91a634b497859b14db97672b5b46
0
Navra 101 Feb 28, 2009 at 12:16

Hi,
why is

?- B=[1 [2]].

B = [1, 2]

and

?- B=[1 2].
B = [1 2]
Why is ?- B=[1 [2]]. not B=[1 [2]] ?

Thanks for any answers.

3 Replies

Please log in or register to post a reply.

4413189eb92ecb0c72aa193596bda383
0
Trap_D 101 Feb 28, 2009 at 17:25

Because as in Lisp, a list in Prolog is of the form [H | T] where T is a list.
[1|2] is not a proper list, it’s equivalent as (1.2) in Lisp.

B = [1 [2]] is the same as [1 [2 []]]
5afb91a634b497859b14db97672b5b46
0
Navra 101 Mar 01, 2009 at 10:15

I got it.

Thanks ;)

00000000000000000000000000000000
0
Anonymous May 31, 2010 at 18:26

Programming is something that I hate, but can not help it, I still gotta do it. you know - school assignment.

Its so tough man.

Thanks for the answer! was facing same query but could not find an answer to it..very useful post.

Thank god there are some guys who can help me do my homework :D