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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:51:26+00:00 2026-05-18T08:51:26+00:00

The following piece of Clojure code results in java.lang.StackOverflowError when I call it with

  • 0

The following piece of Clojure code results in java.lang.StackOverflowError when I call it with (avg-bids 4000 10 5). I try to figure out why, since sum-bids is written as a tail-recursive function, so that should work. Using Clojure 1.2.

Anyone knows why this happens?

(ns fixedprice.core
  (:use (incanter core stats charts)))

(def *bid-mean* 100)

(defn bid [x std-dev]
  (sample-normal x :mean *bid-mean* :sd std-dev))

(defn sum-bids [n offers std-dev]
  (loop [n n sum (repeat offers 0)]
    (if (zero? n)
      sum
      (recur (dec n) (map + sum (reductions min (bid offers std-dev)))))))

(defn avg-bids [n offers std-dev]
  (map #(/ % n) (sum-bids n offers std-dev))) 
  • 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-18T08:51:26+00:00Added an answer on May 18, 2026 at 8:51 am

    map is lazy, and you’re building a very deeply nested mapping of mappings via recur. The backtrace is a bit cryptic, but look closely and you can see map, map, map…

    Caused by: java.lang.StackOverflowError
            at clojure.lang.LazySeq.seq(LazySeq.java:56)
            at clojure.lang.RT.seq(RT.java:450)
            at clojure.core$seq.invoke(core.clj:122)
            at clojure.core$map$fn__3699.invoke(core.clj:2099)
            at clojure.lang.LazySeq.sval(LazySeq.java:42)
            at clojure.lang.LazySeq.seq(LazySeq.java:56)
            at clojure.lang.RT.seq(RT.java:450)
            at clojure.core$seq.invoke(core.clj:122)
            at clojure.core$map$fn__3699.invoke(core.clj:2099)
            at clojure.lang.LazySeq.sval(LazySeq.java:42)
            at clojure.lang.LazySeq.seq(LazySeq.java:56)
            at clojure.lang.RT.seq(RT.java:450)
            at clojure.core$seq.invoke(core.clj:122)
            at clojure.core$map$fn__3699.invoke(core.clj:2099)
            at clojure.lang.LazySeq.sval(LazySeq.java:42)
            at clojure.lang.LazySeq.seq(LazySeq.java:56)
            at clojure.lang.RT.seq(RT.java:450)
            at clojure.core$seq.invoke(core.clj:122)
            at clojure.core$map$fn__3699.invoke(core.clj:2099)
    

    One way to fix it is to put doall around it to defeat laziness.

    (defn sum-bids [n offers std-dev]
      (loop [n n sum (repeat offers 0)]
        (if (zero? n)
          sum
          (recur (dec n) (doall (map + sum (reductions min (bid offers std-dev))))))))
    
    user> (avg-bids 4000 10 5)
    (100.07129114746716 97.15856005697917 95.81372899072466 94.89235550905231 94.22478826109985 93.72441188690516 93.32420819224373 92.97449591314158 92.67155818823753 92.37275046342015)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following piece of Java code. int N = 10; Object obj[] =
The following piece of code shows an Insert table dialog: Dialog d = WordApp.Dialogs[WdWordDialog.wdDialogTableInsertTable];
I have the following piece of code pattern: void M1(string s, string v) {
I have the following piece of code which replaces template markers such as %POST_TITLE%
I've got the following piece of code in an aspx webpage: Response.Redirect(/Someurl/); I also
I used the following piece of code in the service to debug the service
I'm using the following piece of Objective-C code to format a NSNumber, and it
I have the following piece of code in Visual C++ 2005 : : class
I have trouble with the following piece of code. When I go through with
It seems that the following piece of HTML is ignored in IE7 but works

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.