Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define find-n-fib-WHILE
- (var-block 'f1 (const 0) ;f1:=0
- (var-block 'f2 (const 1) ;f2:=1
- (var-block 'tmp (const 0) ;tmp:=0 (pomocnicza do liczenia Fib)
- (comp (while (op '> (variable 'i) (const 0)) ;while(i>0)
- (comp (assign 'tmp (variable 'f2)) ;tmp:=f2
- (comp (assign 'f2 (op '+ (variable 'f1) (variable 'f2))) ;f2:=f1+f2
- (comp (assign 'f1 (variable 'tmp)) ;f1:=tmp (czyli de facto f2)
- (assign 'i (op '- (variable 'i) (const 1))))))) ;i=i-1
- (assign 'i (variable 'f1))))))) ;i=f2 (zwracamy odpowiedź)
- (define (find-n-fib-using-WHILE n)
- (env-lookup 'i (interp find-n-fib-WHILE
- (env-from-assoc-list `((i ,n))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement