Advertisement
tinyevil

Untitled

Feb 26th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. factorial(n:int) : int | effects [] {
  2. int acc = 1; {effect [write acc]} | {effect [write acc]}
  3.  
  4. for ( int i = 1; {effects [write i]} | {effect [write i, write acc]}
  5. i <= n; {effects [read i, read n]} | {effect [write i, read i, write acc]}
  6. i++ {effects [read i, write i]} ){ | {effect [write i, read i, write acc]}
  7. acc *= i; {effects [read i, read acc, write acc]} | {effect [write i, read i, write acc]}
  8. } | {effect [read acc, write acc]} //i goes out of scope, so its effects are dropped
  9. | {effects [read acc]}
  10. return acc; | {effects []} //acc goes out of scope
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement