(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
)
tradurre in c-come il codice
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;
per inciso si dovrebbe essere in grado di vedere che questo codice restituisce il numero di Fibonacci 10
EBNF opzionale/sintassi formale:
La sintassi secondo lo Hyperspec è:
(do ({var | (var [init-form [step-form]])}*)
(end-test-form result-form*)
declaration*
{tag | statement}*)
Capire questo richiede la conoscenza di EBNF e grandi blocchi del Hyperspec
AFAIR, "do" è una macro. – zvrba