Prolog: list as tail of a list

3 replies to this topic

#1Navra

New Member

• Members
• 2 posts

Posted 28 February 2009 - 12:16 PM

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]] ?

#2Trap D

Member

• Members
• 55 posts

Posted 28 February 2009 - 05:25 PM

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 | []]]

#3Navra

New Member

• Members
• 2 posts

Posted 01 March 2009 - 10:15 AM

I got it.

Thanks

#4carlodalid1

New Member

• Members
• 5 posts

Posted 31 May 2010 - 06:26 PM

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

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users