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

  • SEARCH
  • Home
  • 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 8448809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:31:48+00:00 2026-06-10T10:31:48+00:00

While exploring various ways of computing factorials in Clojure, I came up with the

  • 0

While exploring various ways of computing factorials in Clojure, I came up with the following (non-idiomatic) function:

(defn factorial-using-do-dotimes [x]
  (do
    (def a 1)
    (dotimes [i x]
      (def a (* a (inc i)))))
  a)

REPL:

user=> (factorial-using-do-dotimes 5)
120

What are the concrete disadvantages of this (aside from “non-idiomatic”)? Performance? Correctness (that is, possible defects)?

  • 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-10T10:31:50+00:00Added an answer on June 10, 2026 at 10:31 am

    Using def inside a function body is not idiomatic, sort-of-but-not-explicitly undefined behavior, and considering the way vars are implemented, using (dotimes .. (def ..)) is quite possibly slower than using (loop ... (recur ...)), especially when you’re using basic types, like numbers, and type-hints.

    The main reason not to do this kind of “dynamic” modification of vars, is that it complicates your code for no good reason. Some much more idiomatic combination of loop/recur and transients should under normal circumstances get you as good a performance as you can get out of clojure. And it will still be thread-safe, predictable and readable.

    Edit: as a concrete defect: your example code does not work correctly when called from multiple threads concurrently.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while exploring jQuery I came up with the following weird script. I don't see
I saw this article recently while exploring various ways to work with images at
I here by post the code why I came across while exploring one technique.
After a few weekends exploring Clojure I came up with this program. It allows
While exploring msdn sites ,most of the condition checking places they are using (NULL
While exploring for scjp questions, I came across this behaviour which I found strange.
I'm using and really enjoying a wicked combination of knockout.js and Script# While exploring
While deveoping a site (using Forms authentication and InProc sessionstate) a frequently run into
While developing an application using gwt in ecliplse crashed. Now the server is running
While recently exploring prezi I realized there have to be better tools than PowerPoint

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.