How the right syntax can help teach recursion
Explaining recursion is a lot easier than writing recursive functions.<p>I can actually describe explicitly why I&#x27;ve occasionally found writing a recursive function hard. In fact I expect a UI could be created that would make it much much easier.<p>Basically, for ordinary functions I&#x27;m able to remember the values stored in each of the variables. (I do not mean a real computation, but the pretend computation I do at all times when programming.)<p>However, with recursive functions, I sometimes find myself having to remember 5 or more levels of these same variables. Therefore if I have 5 variables, I might end up having to hold 25 values in my head; obviously it is less than this since often there is some pattern to the values that aids in remembering them.<p>Additionally, I need to flow the return values back through the functions potentially performing extra computations on them; this can be extra confusing if there were multiple entry-points at a particular recursion level of a function. For example, what line and column number was the function called at, and which block of a function was it within? And, do these values belong to the 7th or 9th call of the function? Due to this I&#x27;m no longer able to rely on my memory, and I don&#x27;t get the cognitive benefits of associating computations to place.<p>Another issue is that if you write some code which never matches its &#x27;base case&#x27; it never finishes computing. This is often difficult to debug, and it can cause your machine to lock up.<p>Perhaps the solution might be:<p>- A table to represent the values within a recursive function. With colour coded cells that show which level of function a value comes from (and whether it was an argument or return from a deeper level). Effectively, the idea is to reassociate computation with &#x27;place&#x27;. Method of Loci.<p>- Some tools in order to troubleshoot the times in which they&#x27;ve misprogrammed the &#x27;base case&#x27;. For example, set a particular recursion depth when developing and exit if this gets reached. Visualise separately how values are advancing towards matching this  &#x27;base case&#x27;.<p>I could probably come up with more, but I need to think concretely again to do so usefully; and I&#x27;d need to experiment with different recursive solutions to find out whether I&#x27;m solving their individual problems.