Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-03-10 Thread Carl Banks
Carl Banks wrote: > I could, however, see myself > using the slightly more complicated descriptor such as this (for a > wholly different reason, though): > > . def call_with_open_file(filename): > . def descriptor(func): > . flo = open(filename) > . try: f(flo) > . fi

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-03-10 Thread Carl Banks
Nick Coghlan wrote: > 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 :) Workarounds: 1. Just use a freaking global, especially

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-03-10 Thread Bengt Richter
On Fri, 25 Feb 2005 19:34:53 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: >Nick Coghlan wrote: >> 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

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-02-25 Thread Nick Coghlan
Steven Bethard wrote: Worth looking at is the thread: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/58f53fe8bcc49664/ Huh - I thought I put something in the original post saying "without resorting to bytecode hacks", but I must have deleted it before sending the messag

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-02-25 Thread Steven Bethard
Nick Coghlan wrote: 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 :) I'm not certain how many use cases really require a full su

Re: Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-02-25 Thread Nick Coghlan
Nick Coghlan wrote: 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 c

Code evaluation at function definition execution time (was Re: Compile time evaluation (aka eliminating default argument hacks))

2005-02-25 Thread Nick Coghlan
Steven Bethard wrote: 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? Basically, yeah. Although I later realised I got the name of the feature I want wrong -

Re: Compile time evaluation (aka eliminating default argument hacks)

2005-02-24 Thread Steven Bethard
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 # [