News for hackers. Stuff that matters.
Re:A few things to remember while coding in Python by anthonyb on Saturday May 19, 2012 @09:02PM (#3997586)
My lisp is a bit rusty, but it looks like what you're doing there is returning a function which gets redefined every time you reuse the function.

The equivalent Python would be something like this:

    def function():
        x = 3
        def internal(x, foo=[]):
            foo.append([7])
            foo.append(x)
            return foo
        return internal(x)
        
    print function()
    print function()
Which does what you would expect:

    [[7], 3]
    [[7], 3]
Re:A few things to remember while coding in Python by ScottBurson on Saturday May 19, 2012 @09:23PM (#3997619)
No. In my example the function is created only once, and called twice.
Re:A few things to remember while coding in Python by anthonyb on Saturday May 19, 2012 @10:06PM (#3997696)
What's that lambda thingo in the middle then? Pretty sure that's another function, redefined every time your function is called.
Re:A few things to remember while coding in Python by Tyr42 on Saturday May 19, 2012 @10:49PM (#3997752)
Yes, the lambda creates the function. Note that defvar does not. So there is still only one function being defined here.
Re:A few things to remember while coding in Python by anthonyb on Saturday May 19, 2012 @11:16PM (#3997806)
Ok, I see now.

You've still got that &optional argument though. I don't see a huge amount of difference from a semantic point of view between that and the Python version though (ie. if x == None: ...).

Re:A few things to remember while coding in Python by derleth on Saturday May 19, 2012 @10:24PM (#3997726)
No, the lambda expression creates the function, which is returned as the value of the let block; defvar just binds the function to a name so we can use it multiple times.