Clojure Loop Head & Tail Split and Recursion on Tail

[quads id=4]
Said we have a Loop like this:

(loop [remaining-parts STARTINGPARTS
         RESULT [RESULTSTARTINGVALUE+TYPE]]
    (if (IFCLAUSE)
     FINALRESULTOUTPUT
     (let [[head & tail] remaining-parts] ;; Splitting in Head & Tail
        (recur tail
               (DOSOMETHINGWITH head ...)))
     )
)

First, we Split in “head & tail” the recursive Value using the “let” Function:

(let [[head & tail] remaining-parts] ;; Splitting in Head & Tail

Then with :

recur tail

The “tail” straight become the recursive Value and so in this case the “remaining-parts”

Leave a Reply

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