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 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
  • 1 View
  • 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

Related Questions

I'm trying to follow the Auth example for Webapp2 that can be found here:
Here is an example that outputs 6 : public static void main(String[] args) {
Here is the example: http://jsfiddle.net/FdT23/4/ The goal is that when you hover your mouse
Here's some example code: class Obj attr :c, true def == that p '=='
Just some example code here, but I have lists of strings that I want
Hi I have a code example available here: http://jsbin.com/oxoweh My problem is that I
I'm using the example found here: http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Text_Rendering_01 The issue is that when I specify
I want that find empty tags, here is a example txt =<lol1><><lol2> rgx =
I currently have a csv file that I'm parsing with an example from here:
Checking the datagrid example here http://www.silverlight.net/content/samples/sl4/toolkitcontrolsamples/run/default.html see the datagrid section It says that if

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.