Subject: Re: Removing the first element

From: Lalit Jain <[email-masked]>
Date: Wed, 6 Sep 2000 12:22:28 -0700 (PDT)

I think the fundamental concept you're missing is the difference between
variable assignment and instantiation. Unlike in other languages where you
can assign/reassign a value to a variable, in Prolog, variable get
instantiated ( as opposed to being assigned ). And once a
variable is instantiated you cannot modify/reassign it. (In case of
backtracking though, these instantiations are undone and redone to produce
alternative results).
Hence in your ex. if X=[a,b],
then [Y|X] = X cannot reassign X to [b], becuase X is already [a,b],
hence, the system ends up checking if [Y|[a,b]] = [a,b] which fails.

Hope this helps.
Regards,
Lalit
---							
Lalit Kumar Jain	SavVion Inc.
@ 408-330-3431		http://www.savVion.com
---			

On Wed, 6 Sep 2000, Justice, Randy -CONT wrote:

> I was trying to remove the first element of the list and return the results
> in the parameter.
> I have two rules: test  and test1.   Why don't test1 work?   What is the
> fundamental rule that I am missing??  How does one assign a value to a
> parameter --(with numbers one can use "is") ?
> 
> test(X):-
>    write(X),
>    write('\n'),
>    [Y|Z] = X,
>    write(Y),
>    write('\n'),
>    write(Z).
> 
> test1(X):-
>    write(X),
>    write('\n'),
>    [Y|X] = X,
>    write(Y),
>    write('\n'),
>    write(X).
> 
> ?- test([[1,2],[1,2,3,4]]).
> [[1, 2], [1, 2, 3, 4]]
> [1, 2]
> [[1, 2, 3, 4]]
> 
> Yes
> ?- test1([[1,2],[1,2,3,4]]).
> [[1, 2], [1, 2, 3, 4]]
> 
> No
> 
> 
> Thanks again... 
> 
> Randy
> 
> 
> ----------------
> * To UNSUBSCRIBE, please use the HTML form at
> 
>     http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist
> 
> or send mail to [email-masked] using the Subject: "unsubscribe"
> (without the quotes) and *no* message body.
> 
> ** An ARCHIVE of this list is maintained at
> 
>     http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/
> 
>