Nick Coghlan wrote:
Time for another random syntax idea. . .

So, I was tinkering in the interactive interpreter, and came up with the following one-size-fits-most default argument hack:

[snip]

But consider a syntax like the following:

    def f():
        use x, y from:
            y = x + 1  # [1]
        print x, y

[snip]

Essentially, the function is compiled as usual, and emits code at the location of the 'use' statement equivalent to that for "x, y = <const>". The relevant entry in co_consts is populated by executing the body of the 'use' statement with an implicit "return x, y" at the end. The environment for that execution is the same as that for any function defined at the same level as the containing scope of the 'use' statement (e.g. module level in the example).

So just to clarify, the issue you're trying to address is when you want early binding like function default arguments get, but you don't want to declare the names as function arguments?


If I understand you right, I like the idea, though I'm undecided on your syntax for it at the moment...

STeVe
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to