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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:33:41+00:00 2026-06-13T06:33:41+00:00

How do LISPs or MLs implement tail-call optimization?

  • 0

How do LISPs or MLs implement tail-call optimization?

  • 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-13T06:33:44+00:00Added an answer on June 13, 2026 at 6:33 am

    I can’t speak on the exact implementation details different compilers/interpreters, however generally speaking tail-call optimization operates like this:

    Normally a function call involves something like this:

    1. Allocate stack space for the return
    2. Push your current instruction pointer onto the stack
    3. Allocate stack space for the function parameters and set them appropriately
    4. Call your function
    5. To return it sets it’s return space appropriately, pops off the instruction pointer it should be returning to and jumps to it

    However when a function is in tail position, which pretty much means you are returning the result of the function you are about to call, you can be tricky and do

    1. Re-use the stack space allocated for your own return value as the stack space allocated for the return value of the function you are about to call
    2. Re-use the instruction pointer you should be returning to as the instruction pointer that the function you are about to call will use
    3. Free your own parameters stack space
    4. Allocate space for the parameters and set appropriately
    5. Set the value of your parameters
    6. Call your function
    7. When it returns, it will be returning directly to your caller.

    Note that #1 and #2 don’t actually involve any work, #3 can be tricky or simple depending on your implementation, and 4-7 don’t involve anything special from the function you are calling. Also note that all of this results in a 0 stack growth with respect to your call stack, so this allows for infinte recursion and generally speeding things up a little.

    Also note that this kind of optimization can be applied not only to directly recursive functions, but co-recursive functions and in fact all calls that are in tail position.

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

Sidebar

Related Questions

Do any lisps support nested s-expression on their head? For example ((f 2) 3
In various Lisps a proper list is either nil (a null value) or a
How come most Lisps and Schemes are dynamically typed? Does static typing not mix
I'd like to implement a Lisp interpreter in a Lisp dialect mainly as a
I've heard that most lisps support saving image of running program into file. Does
I have a passing knowledge of other Lisps (particularly Scheme) from way back. Recently
Can you give me some examples of tasks unsuited for dynamically scoped lisps? I'm
If I understand correctly Clojure can return lists (as in other Lisps) but also
Whilst starting to learn lisp, I've come across the term tail-recursive . What does
Lists say I have a list List<int> {1,2,3,4,5} Rotate means: => {2,3,4,5,1} => {3,4,5,1,2}

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.