From ok@atlas.otago.ac.nz Tue Mar 27 04:26:29 2001
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f2R2QR326578
	for <prolog@swi.psy.uva.nl>; Tue, 27 Mar 2001 04:26:28 +0200 (MET DST)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id OAA23684;
	Tue, 27 Mar 2001 14:26:13 +1200 (NZST)
Date: Tue, 27 Mar 2001 14:26:13 +1200 (NZST)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200103270226.OAA23684@atlas.otago.ac.nz>
To: h2000500@bits-pilani.ac.in, ok@atlas.otago.ac.nz
Subject: Re:  [SWIPL] biginer's question.
Cc: prolog@swi.psy.uva.nl

Prasad Manjre <h2000500@bits-pilani.ac.in> is still struggling:
    As you have quoted in your example, I created another list & stored the
    rest of list into that i.e
    X1= ([1,3,4])
    But while using this list in the another loop,as soon as the control
    moves to that list the compiler treats X1 as new variable & the values
    stored in it in the previous loop gets lost.& the compiler treats this X1
    as the empty list.
    So will you guide me to use the contets stored in the list X1 to use it
    for the another loop?

I find it very difficult to understand this.
If a ".ac.in" site is some kind of tertiary educational institution
(as a ".ac.nz" site is), surely there is some kind of library with at
least one good Prolog textbook in it?

To understand any programming language, you have to understand its
rules about variable names.  Most programming languages say that a
name stands for a particular thing only within a certain chunk of
text (typically a procedure) where it is declared.  Prolog is just
the same.  A Prolog variable name is visible only within a SINGLE
clause.  Thus in

    p(X) :- q(X, Y), r(Y).
    p(X) :- w(Y), v(Y, X).

there are *TWO* variables called X (one in the first clause and one
in the seocnd) and *TWO* variables called Y (one in the first clause
and one in the second).  There are only two ways you can transmit
information from one clause to another:
 - put it in the mutable data base (slow, easy to get wrong)
 - pass it as a parameter (fast, preferred).

Prolog variables are not like C or Pascal variables where you can store
a value into a variable at any time, even when it HAS a value.  In Prolog,
you can only bind a variable to a value when it doesn't have a value yet.

I think the best thing would be to

 - tell us what problem you are trying to solve (not what difficulty with
   Prolog you are trying to overcome), and
 - show us your actual code.

But reading a good Prolog book would be better still, because it would be
far more helpful to you.

