For Programmers: Free Programming Magazines  


Home > Archive > Scheme > January 2008 > iteration - do with let









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author iteration - do with let
S. Robert James

2008-01-22, 7:35 pm

I'd like to use the do iteration form. However, I'd like to update
several of the variables based on an intermediate variable, which do
doesn't seem to be able to support. That is, define a let body in
which the do step-updates are evaluated.

(I could do this by putting a set! in the command clause - but I'd
like to avoid use of set!).

Any solutions?
Jussi Piitulainen

2008-01-23, 4:35 am

S. Robert James writes:

> I'd like to use the do iteration form. However, I'd like to update
> several of the variables based on an intermediate variable, which do
> doesn't seem to be able to support. That is, define a let body in
> which the do step-updates are evaluated.
>
> (I could do this by putting a set! in the command clause - but I'd
> like to avoid use of set!).
>
> Any solutions?


If you can arrange it so that the intermediate variable is computed in
the previous iteration step, do that. Otherwise, I wouldn't use `do'
for this. It's only nice when it is nice; don't make it a mess.

Consider the `named let':

(let foo (... initial bindings ...)
... body where you can call `foo' ...)
Aaron Hsu

2008-01-25, 4:39 am

On 2008-01-22 17:59:16 -0600, "S. Robert James" <srobertjames@gmail.com> said:

> Any solutions?


You may find that foof-loop [1] macros are a better fit for what you
are trying to do.

[1] http://mumble.net/~campbell/scheme/foof-loop.txt
--
Aaron Hsu <arcfide@sacrideo.us>
http://www.sacrideo.us

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com