2021-01-04 04:02:44 +03:00
|
|
|
# This is how you can emulate Python's semantics for default variables.
|
|
|
|
let l = []
|
|
|
|
def foo(x=l):
|
|
|
|
x.append("more")
|
2021-01-04 17:33:43 +03:00
|
|
|
print(x)
|
2021-01-04 04:02:44 +03:00
|
|
|
|
|
|
|
foo() # → ['more']
|
|
|
|
foo() # → ['more', 'more']
|
|
|
|
foo([1,2]) # → [1, 2, 'more']
|
|
|
|
foo() # → ['more', 'more', 'more']
|
|
|
|
foo() # → ['more', 'more', 'more', 'more']
|
|
|
|
foo(['a', 'b']) # → ['a', 'b', 'more']
|