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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:50:47+00:00 2026-05-11T01:50:47+00:00

Here is an example that a forum poster gave, I can’t tell if this

  • 0

Here is an example that a forum poster gave, I can’t tell if this tail optimized. Also, could someone give a laymans description of how a tail optimized version would trump the normal version.

(defun mylength (s)   (labels ((mylength-inner (s x)             (if (car s) (mylength-inner (cdr s) (+ x 1)) x)))           (mylength-inner s 0))) 

A non tail optimized version?

(defun l (s) (if (car s) (+ 1 (l (rest s))) 0)) 
  • 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. 2026-05-11T01:50:48+00:00Added an answer on May 11, 2026 at 1:50 am

    A function can be tail-call optimized if it returns a straight call to itself or no call to itself. The function mylength-inner will return either x or (mylength-inner (cdr s) (+ x 1)), and so it can be tail-optimized.

    This means the compiler can turn it into a loop instead of calling the function recursively. Either return x, or assign (cdr s) to s, increment x, and start again at the top. (The Scheme standard requires that implementations be able to do this optimization, while the Common Lisp standard leaves it up to the implementation. Of course, this optimization is a very useful thing, so most implementations will do it.)

    In the non-optimized version, l doesn’t just return a call to l, but rather the result of a call to l with one added. This means it can’t be directly turned into a loop, so all the function calls will have to be made.

    Suppose the compiler wanted to turn l into a loop. There’s no problem with the assignment of (rest s) to s, but where does it put the (1 + ...)?

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

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You can find this in Tools -> Options -> Designers… May 11, 2026 at 11:12 am
  • added an answer Add an update method to your ClassA class ClassA {… May 11, 2026 at 11:12 am
  • added an answer Not possible. There is no inheritance with enums. You can… May 11, 2026 at 11:12 am

Related Questions

Here is an example that a forum poster gave, I can't tell if this
Here is an example: <h:outputText value=#{myBean.myMoney}> <f:convertNumber type=currency currencySymbol=$ /> </h:outputText> Given that I
Here is an example of what I've got going on: CREATE TABLE Parent (id
Here is an example of polymorphism from http://www.cplusplus.com/doc/tutorial/polymorphism.html (edited for readability): // abstract base
My question is pretty vague :o) - But here is an example : When
Anybody have good examples of usability disasters? Here's an example. Hector is a manager
Here's a very simple Prototype example. All it does is, on window load, an
Here is an interesting piece of code that my fellow team members were just
What did I do wrong? Here is an excerpt from my code: public void
I'm a little confused by some PHP syntax I've come across. Here is an

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.