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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:54:34+00:00 2026-05-25T02:54:34+00:00

I am only starting off with clojure, and am stuck thinking how to implement

  • 0

I am only starting off with clojure, and am stuck thinking how to implement a seemingly straightforward functionality.

There is a function generator, which takes (among others) an saver function as an argument. The generator does all sorts of stuff and generates certain data objects regularly, which need to be saved. This saving is supposed to be handled by the saver function, and so the generator calls the saver with the data that needs to be saved, every time data is generated.

Now, one saver function I am to write is one that saves the data to a sqlite db. How should I go about this?

  • One strategy I thought of is to create a connection to the sqlite db in the saver function. Create a new connection every time data is to be saved, save the data (only one row in one table) and close the connection. This seemed to be a bit inefficient. Especially considering the data gets generated every 2-5 secs.

  • Another idea is to keep an open connection as a module-level var, which is set to nil at start. The connection is opened the first time the saver function is called and is reused in the subsequent calls. This seems it would probably be more efficient, but to my knowledge, it would require a def form inside of the saver function. Personally, I don’t enjoy doing that.

  • One more (crazy?) thought I had was to use an agent that saves the connection object, initially set to nil. The saver will be a function that sends data to the agent. The agent, creates the connection the first time it needs it, and saves in its associated data object. This looks like it might work well, but agents aren’t designed for this, are they?

So, how do you people address problem? Is there any other paradigm suited just for this case? Or should I do one of the above?

PS. I spent a good deal of time writing this as it’s very hard to put my problem in words. I’m not sure if I got it all right. Let me know if something is unclear.

  • 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-25T02:54:35+00:00Added an answer on May 25, 2026 at 2:54 am

    your second solution sounds best. if you don’t want to use a mutable Var (created via def) then you could create the connection in a “factory” function as a simple immutable value (so it’s just carried around in the closure):

    (defn sqlite-saver-factory [path]
      (let [db-connection (open-sqlite-connection path)]
        (fn [data]
          (save-to-sqlite db-connection data))))
    ...
    (generator (sqlite-saver-factory path) ...)
    

    disclaimer: i am no great clojure expert – the above is just how i would do this in pretty much any functional language. so perhaps there is a more idiomatic clojure approach.

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

Sidebar

Related Questions

I'm starting off building a site which should be responsive to different screen sizes.
I'm only starting with Android dev, and while the Milestone is a nice device
Windows provides only GetTickCount up to Windows Vista and starting from that OS also
Upon starting my webapp within Tomcat 6.0.18, I bootstrap Spring with only what is
This is starting to piss me off real bad. I have this XML code:
I'm using acts_as_nested_set on a model which is called node. There are multiple lists
Here's an example Haskell FRP program using the reactive-banana library. I'm only just starting
I'm starting on a new scientific project which has a lot of data (millions
I've just finished off an app for the iPhone which, until today, ran fine
I'm going to be starting off with a completely blank page (no elements other

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.