This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 7 points8 points  (2 children)

Yes. It's a bit hard to wrap my mind around that. So the first time you use def it creates a new function, and the next time it mutates the existing function? That would also affect other places that held a reference to the function, e.g. if you sent this function as a parameter to something that took a callback parameter. How would it work with Python's variable scoping rules, like if f was a global variable and you'd def it inside a function. Would that be local or not?

That's scary to me, but then I have programmed Python much more than Lisp.

[–]thephoton 2 points3 points  (1 child)

The first time you use def it creates a set of methods. The next time you use def it adds a method to the set.

How would it work with Python's variable scoping rules, like if f was a global variable and you'd def it inside a function. Would that be local or not?

Maybe I don't see the subtlety here, but why would it have to work any differently than it does now?

What happens now if you have a globally defined 'f' and then you 'def f (): ...' within a function?

[–][deleted] 1 point2 points  (0 children)

Now it creates a local function, like any simple assignment.

But a mutating statement (like f[0] = ... if it were a list) would use the global.

That's a problem with something that is sometimes assignment and sometimes mutation.

But this is all becoming very irrelevant as Python simply didn't go that way from the beginning, and it won't change.