Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.sprintlink.net!in2.uu.net!utcsri!cdf.toronto.edu!news
From: Darrell Grainger <a324grai@cdf.toronto.edu>
Subject: cannot understand do expression syntax
X-Sender: a324grai@eddie
Content-Type: TEXT/PLAIN; charset=US-ASCII
Message-ID: <Pine.SOL.3.90.950923215516.2159F-100000@eddie>
Sender: news@cdf.toronto.edu (Usenet News)
Nntp-Posting-Host: eddie
Organization: University of Toronto Computing Disciplines Facility
Mime-Version: 1.0
Date: Sun, 24 Sep 1995 02:17:40 GMT
Lines: 42

The subject pretty much says it. I'm trying to figure out how the do
expression works. Could someone give me a simple example of the do
expression? 

Here is what my documentation has:

(do ((<var> <init> <step>)
	...)
	(<test> <expr> ...)
	<cmd> ...)

and as an example:

	(let ((x '(1 3 5 7 9)))
	(do ((x x (cdr x))
	     (sum 0 (+ sum (car x))))
	    ((null? x) sum)))

With this are these right? sum is just a variable, right?

<var>	= x
<init>	= x
<step>	= (cdr x)
<test>	= (null? x)
<expr>	= sum
<cmd>	= 

What is this doing? I know the results but I don't really understand
why. What is the (sum 0 (+ sum (car x))) expression doing? I know that
(+ sum (car x)) is taking sum plus (car x) but what is (sum 0 <number>)
doing? Doesn't this mean 'sum' is a procedure? Could this also be
written as

	(let ((x '(1 3 5 7 9)))
	(do ((x x (cdr x))
	     (sum 0 (+ s (car x))))
	    (null? x) s)))

because there are really two uses of 'sum' in the original code?

Thanks for any clarification you could give me.

