Clojure Recur Example

Recur Example with Head and Tail in Clojure Programming

[quads id=8]

Hi! Here I shows you a Simple Recur Example in Clojure Programming Language.

And the recur Function in Clojure is an easy Looping Tool.

It simply repeat the Execution of Function from where is triggered.

Moreover, it redefine the Paramenters given to the Function at each Call.

Finally, a frequent use of recur is in an Head & Tail Recursion.

Featured
  1. Example of recur

    So here is a symbolic recur Example
    With a Head & Tail Looping:

    (defn loop-head-tail [Items Result]
    ...
      (if (CONDITION)
        Result
        (recur 
           (rest Items)
           (DOSOMETHINGWITH (first Items) ON Result)))
    )
    
    The Capitalized entries are just there to mean the Action to yield from some arbitrary Clojure Code.
    When the if Condition is true the main Function is achieved and Result is outputted.
    Else the Function loop-head-tail is called back with (rest Items) and the updated Result as Parameters.

Leave a Reply

Your email address will not be published. Required fields are marked *