Code blocks as parameters

James_Althoff at James_Althoff at
Tue May 1 15:51:02 EDT 2001

Greg writes:
>For a while I've been thinking about making something like
>  func(arg1,arg2):
>    statements
>mean the same as (except for the local function name):
>  def thunk():
>    statements
>  func(thunk,arg1,arg2)
>But then someone is going to want to pass arguments
>to the thunk, and I haven't thought of a good
>syntax for that yet.
>Greg Ewing, Computer Science Dept, University of Canterbury,

perhaps something might be possible along the lines of:

func(arg1,arg2) targ1,targ2:
    statements using targ1 and/or targ2

which would turn into:

def thunk(targ1,targ2):
    statements using targ1 and/or targ2


class MyList:
    def __init__(self,alist):
        self.list = alist
    def do(self,function):
        for member in self.list:

mylist = MyList([1,2,3,4,5])

---- item:
    print item

turns into:

def thunk(item):
    print item

and e.g., without args:

form = Form()
form.setSearchString('black pen')



More information about the Python-list mailing list