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 6877871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:39:11+00:00 2026-05-27T04:39:11+00:00

I started playing with Clojure today and stumbled upon the statement that one could

  • 0

I started playing with Clojure today and stumbled upon the statement that one could change functions dynamically during runtime.
That sounds pretty cool so I wrote a little piece of code using this feature.

(defn ^:dynamic state [x]
   (odd x))

(defn even [x]
  (if (= x 0)
    (println "even")
    (binding [state odd] (parity x))))

(defn odd [x]
  (if (= x 0)
    (println "odd")
    (binding [state even](parity x))))

(defn parity [x]
    (state (dec x)))

It works out fine, but since I am completly new to Clojure I don’t know whether this is
a) clean functional code (since odd and even seem to have sideeffects?)
b) the way changing functions on runtime is supposed to be done

I would appreciate any kind of advice on that! 🙂
-Zakum

  • 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-05-27T04:39:11+00:00Added an answer on May 27, 2026 at 4:39 am

    Use of dynamic bindings is mostly a question of taste, but there are a few considerations:

    Dynamic bindings are pretty much a shortcut for explicitly passing values on the call stack. There are only a few situations where doing that is a totally obvious win; mostly things like passing “global” configuration settings/arguments “through” APIs that don’t support them.

    An API that relies on dynamic bindings is hard to wrap into something more explicit, while the other way around is much easier (and can usually be done semi-automatically).

    Dynamic bindings do not play nice with lazy sequences or anything else that evaluates outside of the current call stack (like other threads).

    All in all, I think the “cleaner” functional solution would be to pass state as an argument to parity, but arguments can be made either way.

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

Sidebar

Related Questions

I just started playing around with threading today and I ran into something that
I just started playing with Clojure, and I wrote a small script to help
I have just started playing with the ASP.Net MVC framework, and today I created
Have just started playing with ASP.NET MVC and have stumbled over the following situation.
I just started playing around with the 960 CSS framework and found that it
I started playing around with Pascal Script today and I cannot find any good
Today I started playing with the MVC 3 Beta. Started with an application from
I recently started playing around with writing Perl (v5.8.8) extensions using XS. One of
I've just started playing with Eclipse RCP. A few things that I would like
I've recently started playing with Silverlight 4, and in one of my projects I'm

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.