On Feb 25, 2004, at 4:02 PM, Skip Montanaro wrote: > > Michael> The "def name [modifiers]:" is unpythonic because: > Michael> * It re-uses the "[]" for a completely new purpose, > unrelated > Michael> to lists or indexing. > > Not necessarily. It names a list of functions to be applied to this > function to get the final definition (I'll leave it to others to > figure out > the order of application :-). In particular, you could probably dream > up > some rather "interesting" list constructors which would allow the > programmer > (or even the user) to modify the behavior at function definition time: > > def is_enabled(m, fname, tracers=os.environ.get("TRACERS", "")): > "ex: TRACERS=func1:trace,func2:count_lines ; export TRACERS" > return tracers.find("%s:%s"%(fname,m.__name__)) != -1 > > modifiers = [trace, profile, count_lines] > > def func1(a,b,c) [m for m in modifiers if is_enabled(m, "func1")]: > ... > > def func2(a,b,c) [m for m in modifiers if is_enabled(m, "func2")]: > ... > > that it would necessarily be good to always use such > complex > constructs, but it might provide some as-yet-unanticipated power for > debugging or other magic. If you are going to add [...] as a function > modifier syntax, I would argue that it should allow the full power of > list > (or generator) comprehensions. I agree with you here, but the patch doesn't do that yet. Right now you would need to do something like: def fnseq(lst): def fnseq(fn): for obj in lst: fn = obj(fn) return fn return fnseq def func1(a,b,c) [fnseq([m for m in ...])]: -bob
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4