From: Luke
Subject: Newbie question (DO Loops in Lisp)
Date: 
Message-ID: <bcqefp$s88$1@online.de>
hello!

I'm not sure about the let and the do concept in Lisp:

why does the following piece of code

(let ((GOAL-STRUCTURE (if first (copy-tree GOAL-STR) GOAL-STR)))
  (do ((G GOAL-STRUCTURE (cdr G)))
    ((null G) GOAL-STRUCTURE)
    (*BODY*)))

NOT do the same as this one?

(do ((G (if first (copy-tree GOAL-STR) GOAL-STR) (cdr G)))
  ((null G) GOAL-STR)
  (*BODY*))

actually I did nothing but omitting a level of indirectness, didn't I?

GOAL-STR and first are Variables, the procedure gets by invoking it.

Thanks in advance!

Luke

From: ·············@attbi.com
Subject: Re: Newbie question (DO Loops in Lisp)
Date: 
Message-ID: <8yrzchav.fsf@attbi.com>
"Luke" <···················@gmx.de> writes:

> hello!
>
> I'm not sure about the let and the do concept in Lisp:
>
> why does the following piece of code
>
> (let ((GOAL-STRUCTURE (if first (copy-tree GOAL-STR) GOAL-STR)))
>   (do ((G GOAL-STRUCTURE (cdr G)))
>     ((null G) GOAL-STRUCTURE)
>     (*BODY*)))
>
> NOT do the same as this one?
>
> (do ((G (if first (copy-tree GOAL-STR) GOAL-STR) (cdr G)))
>   ((null G) GOAL-STR)
>   (*BODY*))
>
> actually I did nothing but omitting a level of indirectness, didn't I?
>
> GOAL-STR and first are Variables, the procedure gets by invoking it.

In the first one, if FIRST is true, then GOAL-STRUCTURE is bound to a
copy of the GOAL-STR tree.  The DO operates on that copy and the
return result is that copy.

In the second one, if FIRST is true, then G is bound to a copy of
GOAL-STR, but the value returned by the DO is the *original* GOAL-STR,
not the copy.

If *BODY* mutates the structure (or the copy), these will produce
different results.

> Thanks in advance!

Why not thank people when you get an answer?
 
From: Luke
Subject: Re: Newbie question (DO Loops in Lisp)
Date: 
Message-ID: <bcrupc$uv6$1@online.de>
> > Thanks in advance!
>
> Why not thank people when you get an answer?
>

Thank you very much! ;-)