First class lexical closures

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Mon Oct 15 17:10:40 EDT 2007


Jon Harrop a écrit :
> Just debating somewhere else whether or not Python might be considered a
> functional programming language. Lua, Ruby and Perl all seem to provide
> first class lexical closures.


def makeadder(x):
   def add(y):
     return x+y
   return add


If that's what you mean, then it a common idiom in Python, yes. You may 
also want to look for 'function decoators' (some syntactic sugor for 
HOFs), and how to define your own callable types (which is just the OO 
equivalent to closures).



More information about the Python-list mailing list