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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:20:39+00:00 2026-06-07T15:20:39+00:00

Recently I was writing a little CLI script which needed to repeatedly read dates

  • 0

Recently I was writing a little CLI script which needed to repeatedly read dates from the console (the number of dates to read was calculated and could be different each time). Sample Ruby code to give you the idea:

dates = x.times.collect { print "Enter date: "; Date.parse(gets.chomp) }

Just for the heck of it, I wrote the script in Clojure, and wound up using some rather ugly code with swap! and loop...recur. I’m wondering what the cleanest way to achieve the desired effect in Clojure would be. (Clojure does have dotimes, but it doesn’t retain the values returned from evaluating the body… as might be expected from a language which emphasizes pure functional programming.)

  • 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-07T15:20:42+00:00Added an answer on June 7, 2026 at 3:20 pm

    If your goal is to end up with a sequence of exactly x dates entered by user then:

    (for [line (repeatedly x read-line)] (DateFormat/parse line))
    

    or using map:

    (map DateFormat/parse (repeatedly x read-line))
    

    Beware of lazy sequences in Clojure: user will be asked to enter more dates as they are needed. If your goal is for user to enter all dates at once (say at startup) then use doall:

    (map DateFormat/parse (doall (repeatedly x read-line)))
    

    This will read all dates at once, but will parse them lazily still, so date format validation could fail much later in your program. You can move doall one level up to parse promptly as well:

    (doall (map DateFormat/parse (repeatedly x read-line)))
    

    And you can use a helper function to read line with prompt:

    (defn read-line-with-prompt [prompt]
      (print prompt)
      (read-line))
    

    Then replace read-line with either:

    #(read-line-with-prompt "Enter date: ")
    

    or

    (partial read-line-with-prompt "Enter date: ")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently, I was writing a class in which I discovered that I could reduce
I'm very new to Ruby. I've recently finished writing a simple script, which uses
I just recently found myself writing this line of code, which i did not
I am from procedure programming background, end up writing TSQL recently with my new
recently I'm writing some functions that I take from Haskell and translate into Java.
I have recently finished writing a script for Maya that exports a file containing
I have been using rspec for a little while and recently switched style from
I was recently quickly writing this little function 5 minutes ago when i got
I downloaded Flash Builder from here : Download I recently started writing some small
Recently I've found myself writing methods which call other methods in succession and setting

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.