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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:32:20+00:00 2026-06-01T07:32:20+00:00

I write this function, but what’s its return value. (defn read-data [file] (let [code

  • 0

I write this function, but what’s its return value.

(defn read-data [file]
  (let [code (subs (.getName file) 0 3)]
    (with-open [rdr (clojure.java.io/reader file)]
      (drop 1 (line-seq rdr)))))

(def d (read-data "data.db"))

It’s OK til now. But when I want print this out.

(clojure.pprint/pprint d)

I got a exception:

Exception in thread "main" java.lang.RuntimeException: java.io.IOException: Stream closed

so I confused, what’s wrong? The return value isn’t a list? How to debug in this situation as an newbie?

Thanks!

  • 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-01T07:32:21+00:00Added an answer on June 1, 2026 at 7:32 am

    The problem is that line-seq is lazy and that the reader is closed by the time it is evaluated.

    That means all the lines need to be read within the scope of your with-open. One option is to force the full evaluation of line-seq by using doall, as shown below.

    (drop 1 (doall (line-seq rdr)))
    

    A potential problem with this approach is that you’ll get an OutOfMemoryError if the file is larger than the available memory. So, depending on what you are trying to accomplish, there might be other less memory-intensive solutions.

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

Sidebar

Related Questions

I'm just wondering if there is a best case to write this code: $('#set_duration_30').click(function(event)
I know it's pretty simple to write this function in javascript, but for a
i have a code like this <script>$(document).ready(function(){ var myPlayList = []; //document.write(whatTo); //New instance
I'm having difficultly figuring out how to write this block of code... function myFunction(x,y,z)
It is valid JavaScript to write something like this: function example(x) { Here is
I am a Ruby newbie. How can I write better for this function? can
I'm trying to write a calendar function like this function get_date($month, $year, $week, $day,
So I know I can write my own HTML-encoding function like this: function getHTMLEncode(t)
So, I was trying to write a function like this: void append_to_stream(std::ostream &stream) {
Somebody write this function void strToUpper(char *p) { while (*p) { *p = TOUPPER(*p);

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.