3 ms·
I read The Little Schemer, twice! It's a wonderful fun book that I recommend to anyone. When I'm going through the book and playing around with Scheme I "get"
by arp242 3y ago
I read The Little Schemer, twice! It's a wonderful fun book that I recommend to anyone.
When I'm going through the book and playing around with Scheme I "get" recursion. Then I put the book down and go back to "real" programming and somehow this just gets lost.
Maybe it's just a matter of more practice, but it's never come naturally to me.
Dijkstra famously wrote that "it is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration."
I started with BASIC. Maybe Dijkstra was right.
- sparkie 3y agoOnce you get used to it, the overwhelming majority of cases you don't actually need to manually write recursive style functions - you start thinking in terms of `map`, `zip`, `unzip` `fold`, `unfold`, `scan`, `init`, `filter`, `take` and `drop`. There are various other related methods but they can usually all be implemented in terms of these. As for non-recursive styles of iteration, I use F# as my primary language and every time I write a loop I have to consult the manual to remind myself of the exact syntax because it's so rare that I actually use them. Usually `iter` does the trick.
- arp242 3y ago"Regular" functional programming is fine, mostly it's just "apply a function to a list of values" (things like fold, which seems like reduce, is a bit more involved, but not much). It's the "factorial in recursive style" type of stuff that trips me up. I can read imperative code like I would read a book: I just do (assuming I'm familiar with the language), but this sort of recursive stuff just trips me up, never mind actually writing it.
- rmckayfleming 3y agoWhat do you mean "factorial in recursive style"? Like recursive with an accumulator?