Code blocks as parameters (Re: what's in a name (was Re: using lambda to print everything in a list))

Roman Suzi rnd at onego.ru
Tue May 1 03:10:18 EDT 2001


On Tue, 1 May 2001, Greg Ewing wrote:

>James_Althoff at i2.com wrote:
>>
>> window.showWaitCursorDuring:
>>     line1-of-code
>>     line2-of-code
>>     . . .
>>     lineN-of-code
>
>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)

It's the scheme proposed earlier:

let:
  a = 1
  b = 2
  c = 3
in:
  statements

but used in a different way:

let:
  def thunk():
    suite
in:
  func(thunk,args...)

If you want arguments, then Python need a syntax
for functions with partially binded args (as in pure functional
languages).

Like this:


func(partially_bind(thunk, a5=3, a6=4), arg1, arg2)

def partially_bind(f, **args):
  def new_func(myargs, binded_args=args):
    return f(myargs, binded_args)
  return new_func

(the syntax is not correct, because myargs and binded_args
are to be mixed somehow)

But all the above (quite normal for "functional programmers"
will make crazy most of usual programmers.

In fact, in some cases (when we bind only known number of
parameters), the above scheme is reality. All this is called
(if I am not mistaken) higher class functions
(functions on functions).


>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.
>
>

Sincerely yours, Roman Suzi
-- 
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Tuesday, May 01, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "Caterpillar: Scratching post." _/





More information about the Python-list mailing list