
One thing I used to do is to use for
with (in-naturals)
, but that’s probably not the best way to do things since it obscures what you really want to do.
What’s wrong with the while loop you linked above? What problems do you get with typechecking?

sorawee: I was getting an error saying something along the lines of “please provide more type annotations, unable to typecheck” and the code it quoted was the entire while loop. I tried adding “Any” annotation for the body and “Boolean” for the condition but I had the same error.
I just changed my code to named lets. I didn’t know about this language feature, it actually made some mutations unnecessary so I guess it’s a better solution.

Use either for
or a so-called ¨named let”.

@sorawee that’s exactly what I was looking for. thanks so much!

I’m not sure SICP can properly inform an algorithms class. I think it’s important to use structures with named fields instead of lists for everything. If your algorithms class includes data structures, you might get some ideas from my course: https://cs.uwaterloo.ca/~plragde/flaneries/FDS/