(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 Fibonacci数
可选EBNF /形式化语法:
根据的语法是:
(do ({var | (var [init-form [step-form]])}*)
(end-test-form result-form*)
declaration*
{tag | statement}*)
理解,这需要的Hyperspec
AFAIR,“do”是一个宏。 – zvrba 2012-04-17 06:07:31