Jump to content


Prolog: list as tail of a list


3 replies to this topic

#1 Navra

    New Member

  • Members
  • Pip
  • 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]] ?

Thanks for any answers.

#2 Trap D

    Member

  • Members
  • PipPip
  • 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 | []]]

#3 Navra

    New Member

  • Members
  • Pip
  • 2 posts

Posted 01 March 2009 - 10:15 AM

I got it.

Thanks ;)

#4 carlodalid1

    New Member

  • Members
  • Pip
  • 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