Re: A question about list

"Gregory Bourassa" <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
Yang,

First the notion of "assign its value" is not very natural in Prolog.  Be aware, if the
variable is already "bound" to a value, you CANNOT assign a new value to it in standard
Prolog.    If Var is previously unbound,  your answer is incredibly simple:

  List = [Var | _]

Prolog's pattern matching ensures that Var is bound to the value of the first element in List.

Regards.

Gregory Bourassa



On Oct 23, "=?gb2312?B?1dTR9A==?=" <[email protected]> wrote:
Hi, all:
    I am a beginner in GNU prolog and now encounter a problem. Given a list that has been
instantiated, I want to get its first element and assign its value to a variable. How can
I do it? I have tried nth(1, List, Var), but it does not help. Could any body tell me?

Zhao,Yang
2006-10-24
_______________________________________________
Users-prolog mailing list
[email protected]
<a
href='http://lists.gnu.org/mailman/listinfo/users-prolog'>http://lists.gnu.org/mailman/listinfo/users-prolog</a>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.