fork download
  1. func makeIncrementer(forIncrement amount: Int) -> () -> Int {
  2. var runningTotal = 0
  3. func incrementer() -> Int {
  4. runningTotal += amount
  5. return runningTotal
  6. }
  7. return incrementer
  8. }
  9. let incrementBySeven = makeIncrementer(forIncrement: 7)
  10. print(incrementBySeven())
  11. print(incrementBySeven())
  12.  
  13. //https://pt.stackoverflow.com/q/453891/101
Success #stdin #stdout 0s 7548KB
stdin
Standard input is empty
stdout
7
14