Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9112967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:51:41+00:00 2026-06-17T03:51:41+00:00

pure recursion is a made-up term here, please forgive. Here are two examples using

  • 0

“pure recursion” is a made-up term here, please forgive.

Here are two examples using two different recursion approaches. What are the guidelines of usage of one over another?

(defn take-while
  "Returns a lazy sequence of successive items from coll while
  (pred item) returns true. pred must be free of side-effects."
  {:added "1.0"
   :static true}
  [pred coll]
  (lazy-seq
   (when-let [s (seq coll)]
       (when (pred (first s))
         (cons (first s) (take-while pred (rest s)))))))

(defn take-last
  "Returns a seq of the last n items in coll.  Depending on the type
  of coll may be no better than linear time.  For vectors, see also subvec."
  {:added "1.1"
   :static true}
  [n coll]
  (loop [s (seq coll), lead (seq (drop n coll))]
    (if lead
      (recur (next s) (next lead))
      s)))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:51:43+00:00Added an answer on June 17, 2026 at 3:51 am

    A few factors to consider:

    • loop/recur doesn’t consume stack space – so it’s the right choice if you are going to do deeply nested recursion that might otherwise cause a StackOverflowError
    • loop/recur is faster – it’s one of the most efficient constructs in Clojure, done correctly it should match the speed of an equivalent for loop in Java code
    • normal recursion is more idiomatic – on average it tends to give you clearer, more functional code whereas loop/recur tends to push you more towards an imperative, iterative style
    • loop/recur has more restrictions – you can only recur in tail position, you can’t do mutual recursion between two different functions, etc. Sometimes it simply isn’t possible to make loop/recur work, at other times you may need to contort your code to do so.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using pure functional languages can have a lot of benefits over using impure imperatives,
I'm using a pure javascript code and i'm sending a post ajax request using
using pure javascript can i select all a tags with href=#xyz. And also i
In pure javascript (not using JQuery/dojo/etc), what is the best/easiest/quickest way to split a
When writing and calling pure subroutines in Fortran 90 using gfortran, how do I
I recently created a pure css drop-down menu using Google tutorials. I have an
In pure Java, I would normally have a function like the one below for
Using pure JavaScript to do inheritance, this is what I usually do: function A()
Using pure virtual methods for faux-interfaces in C++, what happens when a concrete class
I have a pure Winapi application that needs a few new features. One of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.