Skip to content

Instantly share code, notes, and snippets.

@JadenGeller
Created March 26, 2015 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JadenGeller/4d0213fda915a6205229 to your computer and use it in GitHub Desktop.
Save JadenGeller/4d0213fda915a6205229 to your computer and use it in GitHub Desktop.
Swift "call-by-name"
// Example of how call-by-name can be achieved through use of lazy evaluation
let a = [1,2,3]
var i = 1
func f(@autoclosure j: () -> Int) {
println(j()) // -> 2
i = 0
println(j()) // -> 1
}
f(a[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment