I Challenge You to Debug These 7 Lines of Code Under 9 Minutes
&quot;If I lied, you are allowed to insult me abundantly through your favorite channel.&quot;<p>Haha racket can here is how.<p><pre><code>    #lang racket
    
    (define (foo a [methods empty])
      (let ([methods
             (append methods
                     (for&#x2F;list ([i (range 3)])
                       (lambda (x) (+ x i))))])
        (for&#x2F;sum ([m methods])
          (m a))))
    
    (foo 0)  ;; Should be 3
    (foo 1)  ;; Should be 6
    (foo 2)  ;; Should be 9
    (foo 2 (list (lambda (x) x)))  ;; Should be 11
    (foo 0)
    (foo 1)
    (foo 2)


    ;; Now the wrong way

    ;; The lambda capturing wrong
    (define (foo a [methods empty])
      (define i 0)
      (let ([methods
             (append methods
                     (for&#x2F;list ([z (range 3)])
                       ;; modifying the variable i
                       (set! i z) 
                       (lambda (x) (+ x i))))])
        (for&#x2F;sum ([m methods])
          (m a))))

    ;; this one doesn&#x27;t do the default parameter wrong, because
    ;; methods and methods-default share an imutable list and we
    ;; modify only methods so beside &quot;empty&quot; they won&#x27;t share the same
    ;; reference anymore, to get it wrong we should use a mutable list
    ;; (doesn&#x27;t exist in racket).
    (define foo
      (let ([methods-default empty])
        (lambda (a [methods methods-default])
          ;; (printf &quot;~a ~a\n&quot; (length methods) (length methods-default))
          (define i 0)
          (for ([z (range 3)])
            (set! i z)
            (set! methods (cons (lambda (x) (+ x i))
                                        methods)))
          (for&#x2F;sum ([m (append methods methods-default)])
          (m a)))))

    ;; So i use a box to make it mutable.
    (define foo
      (let ([methods-default (box empty)])
        (lambda (a [methods methods-default])
          ;; (printf &quot;~a ~a\n&quot; (length (unbox methods)) (length (unbox methods-default)))
          (define i 0)
          (for ([z (range 3)])
            (set! i z)
            ;; methods and methods-default share the same reference of box.
            (set-box! methods (cons (lambda (x) (+ x i))
                                    (unbox methods))))
          (for&#x2F;sum ([m (unbox methods)])
            (m a)))))

</code></pre>
The moral of the story, language design matter, immutable by default is good, lexical scoping is good, binding over variable is good, ruby, python, php and javascript (the languages the author mention) are bad in that regards.<p>One thing php, ruby, python (but not javascript) has good over racket their identatation tend to be flat and racket (let form, no return statement) tend to go all the way to the right.