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>





_______________________________________________
Users-prolog mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/users-prolog

Reply via email to