Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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]


No. In my example the function is created only once, and called twice.


What's that lambda thingo in the middle then? Pretty sure that's another function, redefined every time your function is called.


Yes, the lambda creates the function. Note that defvar does not. So there is still only one function being defined here.


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: ...).


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: