Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;recursive functional
- (let ! (proc (n)
- (? (= n 0)
- 1
- (* n (! (+ n (- 1))))
- )
- ))
- ;recursively-defined iterative functional
- (let ! (proc (n)
- (let iter-fact (proc (a n acc)
- (? (= a n)
- (* acc n)
- (iter-fact (+ a 1) n (* a acc))
- )
- ))
- (iter-fact 1 n 1)
- ))
- ;iteratively-defined (procedural)
- (let ! (proc (n)
- ;these are just INITIAL values, the loop cannot change them in this scope, it will bind to the same value in its own scope and change within that
- (let a 1)
- (let acc 1)
- (let loop (proc emp
- (? (= a n)
- (* acc n)
- (begin
- (let acc (* a acc))
- (let a (+ a 1))
- (loop)
- )
- )
- ))
- (loop)
- ))
Add Comment
Please, Sign In to add comment