Parameterized Functions without Classes

Hung Jung Lu hungjunglu at yahoo.com
Tue Jun 29 12:59:00 EDT 2004


Jacek Generowicz <jacek.generowicz at cern.ch> wrote:
> hungjunglu at yahoo.com (Hung Jung Lu) writes:
> > I have counted 7 messages in the thread, so far. How come no one
> > mentioned the keyword "closure"?
> 
> I was tempted, but realized that this would only lead to me producing
> a combination of my 3 favourite c.l.py rants, so I refrained.

How about a codeblock-based language that does the following:

f = function( args={x;y;z=g(5);}, deco={synchronized;},
              init={.static=1;}, code={

        w = x+y+z+.static;
        .static += 1;
        w;

    });

f(1,2,3) # returns 7
f(1,2,3) # returns 8

(a) "args" codeblock is executed in such a way that each additional
name is used to build up the argument list of the function. (Special
setattr()/setslot() function is used, if you know what I mean.)

(b) "deco" codeblock builds up names to be used for special decorated
features.

(c) "init" codeblock is run only the first time the function is
invoked.

(d) "code" is the regular codeblock of the function. The return value
is the value of the codeblock, which is the value of the last
expression.

(f) functions are self-aware. The "self" name is optional: an initial
dot suffices. This is enough to take of closure needs, I think.

(g) functions are built by using the "function" function. Don't ask me
chicken-and-egg questions.

regards,

Hung Jung



More information about the Python-list mailing list