Function object: Difference between revisions

Content deleted Content added
m In Ruby: Fix spelling of RubyKaigi
Use Python 3 to demonstrate closures in Python; the Python 2 version is largely obsolete and doesn't add much value to the article
Line 633:
 
Since functions are objects, they can also be defined locally, given attributes, and returned by other functions
,<ref>[https://docs.python.org/3/reference/compound_stmts.html#function-definitions Python reference manual - Function definitions]</ref> as demonstrated in the following two examplesexample:
 
<source lang=Python>
def Accumulator(n):
def inc(x):
inc.n += x
return inc.n
inc.n = n
return inc
</source>
 
Function object creation using a [[Closure (computer science)|closure]] referencing a [[non-local variable]] in Python 3:
 
<source lang=Python3>