1. why do you say they're not like lisp closures?
    Someone could please explain this to me ?
      posted by riffraff at 01:45:31 AM on January 14, 2004  
  2. I am not a language lawyer, but they *seem* very different to me. I think of a Lisp/Scheme closure as keeping an environment around:

    (define (adder n)
      (lambda (x) (+ x n)))
    (define addone (adder 1))
    (addone 4)
    ;; 5

    When you call adder, it returns a function that keeps the current environment (containing the variable n) around.

    In my mind, this seems very different from:

    list.map { x | x*2 }

    where you pass a piece of executable code around. Then again, maybe I'm wrong. According to FOLDOC:

    "In a reduction system, a closure is a data structure that holds an expression and an environment of variable bindings in which that expression is to be evaluated."

    Maybe it's the same idea, with different notions and different ways to approach it.
      posted by Hans at 10:44:38 AM on January 14, 2004  
  3. I think what happens in the example is that the block in the for-statement becomes a closure. This closure is passed to the generator function as the parameter "yield".

    When yield is called, the closure is executed with the unbound x set to value passed in the call.

    I don't think the syntax is that elegant -- it's a bit cryptic. I guess they wanted something that looked as much as a regular for-statement as possible.
      posted by Niklas at 07:04:50 AM on January 15, 2004  
  4. I think that syntax is really clear. And I think they cloned ruby's that copied Smalltalk's one.
    BTW, that are real closure.
    You should be able to do:
    a=10
    list.each{x| a=a+x}


      posted by lsr at 04:31:56 PM on January 17, 2004