Last active
August 7, 2017 12:45
-
-
Save simenge/23af8f3a7789ad6f641c09b1f65ee2b9 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
# Ruby, no bueno | |
a = 1 | |
def f() | |
a=2 | |
end | |
puts a # => 1 | |
# Ruby, works | |
a = 1 | |
__sym123 = binding | |
f = lambda do | |
__sym123.eval("a=2") | |
end | |
f.call | |
puts a # => 2 | |
# Python, hacky | |
a = 1 | |
def f(): | |
global a | |
a = 2 | |
print(a) # => 2 | |
# Also Python, also hacky af | |
def f(): | |
a = 1 | |
def g(): | |
nonlocal a | |
a = 2 | |
g() | |
print(a) # => 2 | |
; Lisp, works | |
(def a 1) | |
(def (f) | |
(set! a 2)) | |
(f) | |
(puts a) ; => 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment