(do ((n 0 (1+ n)) ;declares n, initially 0, n+1 each subsequent iteration)
(cur 0 next) ;declares cur, initially 0, then old value of next
(next 1 (+ cur next))) ;declares next, initially 1, then the sum of (the old) cur and next
((= 10 n) ;end condition (ends when n = 10)
cur) ; return value
;empty body
)
translating into c-like code
for(n=0, cur=0, next=1 ;
!(n == 10) ;
n=old_n+1, cur=old_next, next = old_cur + old_next)
{
//do nothing
old_n = n;
old_cur = cur;
old_next = next;
}
return cur;
incidentally you should be able to see that this code returns the 10th Fibonacci number
Optional EBNF/formal syntax:
The syntax according to the Hyperspec is:
(do ({var | (var [init-form [step-form]])}*)
(end-test-form result-form*)
declaration*
{tag | statement}*)
Understanding this requires knowledge of EBNF and big chunks of the Hyperspec
old_
vars to simulate parallel assignment! Just to neat-pick: your Lisp code is mis-aligned and has one extra closing parenthesis; your C code is missing the ending semicolon. :) – Lachus