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.
I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
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.
I remember the exact moment I understood recursion. I was sitting on this bench, and trying to wrap my head around this function:
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.
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.
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.