Created
April 25, 2010 17:14
-
-
Save jashkenas/378545 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The Ruby... | |
def change_state(object_id, new_state) | |
object = find(object_id) | |
object.state = new_state | |
object.save | |
object | |
end | |
# The CoffeeScript with "returning"... | |
change_state: (object_id, new_state) -> | |
returning object: find object_id | |
object.state: new_state | |
object.save() | |
# The CoffeeScript with named result parameters... | |
change_state: (object_id, new_state) -> (object) | |
object: find object_id | |
object.state: new_state | |
object.save() | |
# An example from the language implementation with "returning"... | |
free_variable: -> | |
returning @temp_var | |
while @check @temp_var | |
ordinal: 1 + parseInt @temp_var.substr(1), 36 | |
@temp_var: '_' + ordinal.toString(36).replace(/\d/g, 'a') | |
@variables[@temp_var]: 'var' | |
# An example from the language implementation with named result parameters... | |
free_variable: -> (@temp_var) | |
while @check @temp_var | |
ordinal: 1 + parseInt @temp_var.substr(1), 36 | |
@temp_var: '_' + ordinal.toString(36).replace(/\d/g, 'a') | |
@variables[@temp_var]: 'var' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment