Advertisement
Guest User

Untitled

a guest
May 5th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.94 KB | None | 0 0
  1. (define find-n-fib-WHILE
  2.   (var-block 'f1 (const 0)                                             ;f1:=0
  3.    (var-block 'f2 (const 1)                                            ;f2:=1
  4.     (var-block 'tmp (const 0)                                          ;tmp:=0 (pomocnicza do liczenia Fib)
  5.      (comp (while (op '> (variable 'i) (const 0))                      ;while(i>0)
  6.             (comp (assign 'tmp (variable 'f2))                         ;tmp:=f2
  7.              (comp (assign 'f2 (op '+ (variable 'f1) (variable 'f2)))  ;f2:=f1+f2
  8.               (comp (assign 'f1 (variable 'tmp))                       ;f1:=tmp (czyli de facto f2)
  9.                     (assign 'i (op '- (variable 'i) (const 1)))))))    ;i=i-1
  10.            (assign 'i (variable 'f1)))))))                             ;i=f2 (zwracamy odpowiedź)
  11.  
  12. (define (find-n-fib-using-WHILE n)
  13.   (env-lookup 'i (interp find-n-fib-WHILE
  14.                          (env-from-assoc-list `((i ,n))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement