[comp.lang.prolog] representation of infinite lists

lang@othello.PRC.Unisys.COM (Francois-Michel Lang) (07/23/88)

This may sound silly, but I'm stumped.  Any explanations out there?
If I call the goal 

| ?- L = [x|L].

Prolog will very obligingly create an infinite list of x's,
and equally obligingly try to print it out:

| ?- L = [x|L].

L = [x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,
x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,
x,x,x,x,x,x^Cx,x,x,x,x,x,x,x,x,Prolog interruption (h for help)? a
[ Execution aborted ]


| ?- 

However, if I call the goal

| ?- L = [x|L], M = [x|M].

Prolog never gets to the point of printing out the variable bindings,
and just hangs.  There's no loop in the unification, because I can do:


| ?-  trace, L = [x|L], M = [x|M].
[The debugger will first creep -- showing everything (trace)]
   (2) 0 Call (built_in): _32=[x|_32] ? 
   (2) 0 Exit (built_in): [x,x,x,x,x,x,x,x,x,...]=[x,x,x,x,x,x,x,x,x,...] ? 
   (3) 0 Call (built_in): _68=[x|_68] ? 
   (3) 0 Exit (built_in): [x,x,x,x,x,x,x,x,x,...]=[x,x,x,x,x,x,x,x,x,...] ? 

but after the second unification, Prolog just sits there and loops, I suppose.
Can anyone explain this?  This was done in Quintus Prolog V2.2.
----------------------------------------------------------------------------
Francois-Michel Lang
Paoli Research Center, Unisys Corporation lang@prc.unisys.com (215) 648-7256
Dept of Comp & Info Science, U of PA      lang@cis.upenn.edu  (215) 898-9511

ok@quintus.uucp (Richard A. O'Keefe) (07/23/88)

In article <7037@burdvax.PRC.Unisys.COM> lang@othello.PRC.Unisys.COM (Francois-Michel Lang) writes:
>[In Quintus Prolog release 2.2]
>If I call the goal 
>| ?- L = [x|L].
>[he gets the output he expected]
>However, if I call the goal
>| ?- L = [x|L], M = [x|M].

(0) Why not send technical questions about Quintus Prolog to Quintus?
    We're more likely to know the answers than the net.

(1) Undefined is undefined: if you create cyclic terms you're on your own.
    Quintus Prolog makes no pretence of doing anything clever with them.

(2) You've been hit by a feature:  the Quintus Prolog top level, before
    printing out the bindings of the variables, checks to see whether any
    of them are identical.  For example,
	| ?- L = a, M = a.
    prints
	L = M = a
    If QP ever got around to noticing that L and M *are* identical, it
    would print them out as
	L = M = [x,x,x,x,x,x,x,x,....
    The difference between the two examples was that the first had only
    one variable, so there was nothing to check, while the second had two
    variables with isomorphic cyclic values.