Skip to content

Instantly share code, notes, and snippets.

@simenge
Last active August 7, 2017 12:45
Show Gist options
  • Save simenge/23af8f3a7789ad6f641c09b1f65ee2b9 to your computer and use it in GitHub Desktop.
Save simenge/23af8f3a7789ad6f641c09b1f65ee2b9 to your computer and use it in GitHub Desktop.
# 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