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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:36:12+00:00 2026-06-11T09:36:12+00:00

Consider the following code. This code almost implements Chicken Scheme style recursion where most

  • 0

Consider the following code. This code almost implements Chicken Scheme style recursion where most of the time functions are directly called but occasionally there is a more complicated trampolining procedure. However, the code doesn’t quite work correctly. What I really want is a method stackLimitsAlmostReached that returns a boolean value that indicates if there is a danger of a stack overflow. How can I check stack limits, and accomplish Chicken Scheme style recursion in Java?

import java.util.Scanner;

public class Main {

public static abstract class Thunk {
    public abstract Thunk x();

    public final void run() {
        Thunk ip = this;

        while (ip != null)
            ip = ip.x();
    }
}

public static void main(String[] unused) {
    final Scanner scanner = new Scanner(System.in);

    new Thunk() {
        public Thunk x() {
            System.out.println("Hello World!");

            try {
                return this.x();
            } catch (StackOverflowError t) {
                System.out.println("GC!");
                scanner.nextLine();
                return this;
            }
        }
    }.run();
}
}
  • 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-11T09:36:14+00:00Added an answer on June 11, 2026 at 9:36 am

    Hey i may have misunderstood your question , but i think that you must look first for these options (Java wise , but this is isn’t the problem IMO)

    -ss Stacksize to increase the native stack size or
    
    -oss Stacksize to increase the Java stack size,
    

    The default native stack size is 128k, with a minimum value of 1000 bytes. The default java stack size is 400k, with a minimum value of 1000 bytes.

    But what i really feel i should warn you about is that the JVM can’t support tail call optimisation because of it’s security model. Wikipedia .
    Each time you call the same function , you introduce a new stack frame and that’s why
    you run on limits fast. A proper scheme that supports TCO doesn’t actually create a new
    stack frame , it just updates the values and returns to a continuation at the start of the
    current frame. this makes recursion very efficient.

    Even clojure that runs on the JVM suffers from this problem , that’s why it has a lambda
    called recur to handle that limitation.
    check also :
    TCO paper

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

Sidebar

Related Questions

Consider the following code: <?php $conn = mysql_connect('localhost', 'username', 'password'); mysql_select_db('database', $conn); ?> This
Consider the following base code: (function($) { $.fn.myPlugin = function(settings) { return this.each(function() {
Please consider the following code: vector<int> myVector; myVector.push_back(10); myVector.erase(myVector.end()); This code compiles and runs
Consider the following code: // this method should add numbers, the requirements are: //
Consider this following code (that retrieves the response from a HTTP request and prints
Consider the following code: time_t t; t = time( NULL ); elog << timezone:
Consider the following code parts: this is Timing.h: class Timing { public: //creates a
Consider the following code snippet: bool SomeObject::equal(const SomeObject& rhs) const { if (this ==
this might be a bit long so my apologies. consider the following code (i've
Consider the following code : // This code safely publishes the Publishable object public

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.