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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:50:31+00:00 2026-05-30T18:50:31+00:00

I am new to Functional Programming and Clojure, so I am not really sure

  • 0

I am new to Functional Programming and Clojure, so I am not really sure about what to do for a project at University. The project should show the advantage of Clojure STM for banking transactions (Transfer of money from account A to account B).
So I plan to proceed this way:

  1. define initial data, like a matrix of Refs or something better
  2. generate random operations to execute: [
    random-account-source-id(0, N_MAX) ,
    random-account-destination-id(0, N_MAX), random-money (0, 1000) ]
  3. insert the transaction into the data structure
  4. Sync transfer of money from source-id to destination-id for all
    the insertions in the matrix, such as:

    
    for i=0; i lt N; i++;
        synchronize: transfer (matrix[i].source,matrix[i].dest,matrix[i].money)
    

I’m not sure about this, then, maybe:

(defn do-all[]
  (dosync
    (when (pos? N)
      (transfer (get matrix [pos 1], get matrix [pos 2], get matrix [pos 3])))))
  • 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-30T18:50:32+00:00Added an answer on May 30, 2026 at 6:50 pm

    Represent the account with a Ref i.e a Ref for each account and perform the money transfer operation in a dosync operation. Also make sure you dont do any side-effect operation (other than on those Refs) in the dosync operation as it may be retried in case of a conflict while updating refs.

    Update:
    In case you will have the number of accounts fixed then you could use ref of vectors where each ref in the vector is an account and each account is identified by the index in the vector.

    Ex:

    (def total-accounts 100)
    (def accounts (vec (map (fn [_] (ref 100)) (range total-accounts))))
    

    In case you have to dynamically add new accounts and identify them by name then you can use hash map where key is the account id (unique value) and value is the Ref for account balance. You will need to wrap this map in a Ref in case you want to do concurrent operations for adding/removing accounts from multiple threads.

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

Sidebar

Related Questions

I'm new to Boost, but not to functional programming, and I'm trying to see
I'm new to Clojure and functional programming in general. I'm at a loss in
Being relatively new to functional programming, I expend lots of energy wondering is this
I am new to functional programming, and now learn Haskell. As an exercise I
I'm new to javascript (functional programming is okay for me, though) and I am
I am completely new to F# (and functional programming in general) but I see
I'm new to Scheme (via Racket) and (to a lesser extent) functional programming, and
I'm new to Haskell and, in general, to functional programming, and I'm a bit
I'm quite new to that functional programming paradigm, but so far I like it.
There is the whole new paradigm of functional programming, which needs a total change

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.