re: Every developers 'oh my god I get it' moment. VIEW POST


I remember the exact moment I understood recursion. I was sitting on this bench, and trying to wrap my head around this function:

(define sum (lambda (ls)
                (if (null? ls)
                    (+ (car ls) (sum (cdr ls))))))

(sum '(8 6 7 5 3 0 9))


I really had to struggle with the idea that the function added up the whole list without there being any variable that actually held that number.

At some point, my brain pictured a red carpet unrolling infinitely into space, and the light went on. The idea locked into place and I totally understood. I loved that class. (C211) It was a summer session, so it was warm days in flip-flops practicing my tuba, and evenings hanging out in the CS dept computer lab with the other students. Good memories.


Awesome piece of code to bring one back down to Earth. A-ha moment killer. 😉


I was a music student at the time, so programming was completely new and amazing to me.


I think the toughest thing for someone who doesn't know it coming to this code is translating things from "car" and "ls" and "cdr" and so on. In fact, "define", "sum" and "if" are the only words here that are obvious to a newcomer.

code of conduct - report abuse