Re: weird macro params issue
"Jonathan Revusky" <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
On Wed, May 21, 2008 at 11:31 PM, Attila Szegedi <[email protected]> wrote: > On 2008.05.21., at 22:01, Jonathan Revusky wrote: > > > Well, hold on. Established languages that have default parameters, > > like Python, say. Does Python let you do this? I have to check. > > Somehow, my sense of this is that this is not something that Guido > > would care for. > > :-) > > > Larry Wall, OTOH, loves weird stuff like this. > > Double :-) Let me know what you found out. Well, it didn't take much investigation. Truth told, I should have just checked before writing the first response, though I definitely anticipated Guido's opinion correctly. Consider: def foo(x, y=3, z=y) : print x + y + z That doesn't even parse. It fails before even attempting to use it. Traceback (most recent call last): File "./foo.py", line 3, in <module> def foo(x, y=3, z=y) : NameError: name 'y' is not defined Plot thickens. Consider the following program: ######### y = 8 def foo(x, y=3, z=y) : print x + y + z foo(1, 2) foo(1) ########## This outputs: 11 12 IOW, the z=y default parameter uses the y =8 defined in the enclosing scope of the function definition, not the y=2 or the y=3 *parameter*. Note also that if you add the two lines: y=18 foo(1) to the above program, the output is: 11 12 12 It simply uses the value of y as defined at that point as a constant default value. It doesn't change if y changes. I wasn't 100% sure of this, which shows how deep my knowledge of python is, but the above semantics didn't surprise me at all. I have the sense (illusory) that I understand the mindset behind Python. (Kind of reminds me of those Christian fundamentalist bumper stickers you see in the states "What would Jesus do?" except "What would Guido do?") BUt seriously, this really has me thinking that, unless we're in a competition to have the funkiest dynamic language around (perhaps kind of like trying to be more catholic than the pope) we should take a step back from this and just think about how desirable it is really to have these semantics. I would tend to think that the Guido way, how it works in python, is the best, most straightforward option, and we should go that way. There is the matter of this having worked (or kind of) in 2.3. But I can't believe we would break many templates by disallowing it. It's probably fairly rare that people rely on this. JR ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/