From e33a84aaf7e108a3d241bea76a8b735283a68dc1 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Thu, 21 Sep 2017 13:28:54 -0400 Subject: [PATCH] Better explanation of elements of recursion. --- Using-Specter-Recursively.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Using-Specter-Recursively.md b/Using-Specter-Recursively.md index 4727d18..893c717 100644 --- a/Using-Specter-Recursively.md +++ b/Using-Specter-Recursively.md @@ -14,7 +14,7 @@ Here is a simple implementation of factorials in Clojure: ```clojure => (defn factorial [x] - (if (< x 2) + (if (< x 2) 1 (* x (factorial (dec x))))) #'playground.specter/factorial @@ -24,7 +24,10 @@ Here is a simple implementation of factorials in Clojure: Here, the function definition *calls itself* with the symbol `factorial`. You still supply input - the value x - but producing the function's return value requires calling the function itself. -So there are two elements to basic recursion: a name or symbol for the recursion point or function, and input arguments. +We can see that there are up to three elements to basic recursion: + * a name or symbol for the recursion point or function (defn function-name) + * optional input arguments + * the body of the recursion - what you **do** recursively - and, at some point, calling the function by its name # Using Specter Recursively