[Python-3000] Brainstorming: Python Metaprogramming

Ian Bicking ianb at colorstudy.com
Wed Apr 26 18:06:33 CEST 2006


Talin wrote:
>>>Where 'quoted' was some sort of class that behaved like a reference to a
>>>variable. So ?x.set( 1 ) is the same as x = 1.
>>
>>Sounds like lambda x: ...
> 
> 
> More differences than similarities, I think. For one thing, you can't use
> lambda x: ... to assign to x. And while you could possibly overload the
> arithmetic operators on a lambda, you'd have to do it for each lambda
> individually, since lambdas don't have classes.

You mean, you can modify the value of a variable in an a calling 
function using this?  Is that really what you mean?  Because that's 
crazy Tcl talk.

In the case of lambda, you'd have to transform it somehow, like 
make_query(lambda x: ...).  One transformation is filling, so (lambda x: 
x+1)(1) seems (from what you describe) to be like (?x + 1); ?x.set(1)... 
though I'm unclear how you actually use that for something useful.

>>>Moreover, you would want to customize all of the operators on quoted to return
>>>an AST, so that:
>>>
>>>    ?x + 1
>>>
>>>produces something like:
>>>
>>>    (add, quoted('x'), 1)
>>>
>>>...or whatever data structure is convenient.
>>
>>You can match the free variables from the lambda arguments against the 
>>variables in the AST to get this same info.
> 
> 
> I don't understand what this means.

I mean you can look at "lambda x: x+1" and get the AST, and see that "x" 
is an argument to the lambda, and construct something like (add, 
quoted('x'), 1).

> Look, folks, I don't have a concrete proposal here. I'm actually fishing
> for ideas, not looking to have my own ideas validated (or not.) My gut
> tells me that there's something here worth looking into, but I haven't
> put my finger on it yet.
> 
> (Isn't it interesting how often we programmers, who pride ourselves on our
> use of logic and reason, so often use intuition and hunches to solve
> problems?)

That's what everyone does, isn't it?  Mathematicians do this and then 
pretend they didn't by writing up a "proof", but that's just a big lie. 
And don't even get me started on philosophers...


-- 
Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org


More information about the Python-3000 mailing list