Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Compile time evaluation (aka eliminating default argument hacks)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Nick Coghlan, post: 1807173"] Basically, yeah. Although I later realised I got the name of the feature I want wrong - default arguments are evaluated when the def statement is executed, not when the code is compiled. So it's a matter of being able to execute some code in the functions local namespace at compile time. I have my doubts about the feasibility of the syntax I posted, too. A version which the Python compiler and parser should actually be able to handle would be to tack an optional clause on to the front of the function definition statement: using x, y from: # Again, the right syntax for early binding is not clear y = x + 2 def f(): print x, y (Similar to some of the ideas about statement local namespaces that were kicking around a while back, but in this case specific to function definitions) Anyway, if others agree that the ability to execute a suite at def exeuction time to preinitialise a function's locals without resorting to bytecode hacks is worth having, finding a decent syntax is the next trick :) Cheers, Nick. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Compile time evaluation (aka eliminating default argument hacks)
Top