(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
)
Cライクなコードに変換
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;
ちなみに、このコードが 10 番目のフィボナッチ数を返すことがわかるはずです。
オプションの EBNF/正式な構文:
Hyperspecに従った構文は次のとおりです。
(do ({var | (var [init-form [step-form]])}*)
(end-test-form result-form*)
declaration*
{tag | statement}*)
これを理解するには、EBNFと Hyperspec の大きなチャンクに関する知識が必要です。