c++
int loop(int x, int y, int z) {
int result = 0;
for ( int i = x; i < y; i+=z ) { result += i; }
return result; }
Just i try that by scheme
(letrec ((my-loop (lambda (a b c)
(begin
(let ((i a) (s 0))
(if (< i b)
(set! s (+ s i)) s))))))(my-loop (+ a c) b c))
please write correct code of scheme....
Here's a straightforward translation to a
do
loop:However, many Schemers find
do
loops to be distasteful. So here's an identical loop that uses namedlet
, which is in fact what thedo
is likely to expand to:which is likely to expand to:
which then expands to:
Yay macros! Choose the version you like best; most Schemers I know prefer the second one.