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

The Archive Base Latest Questions

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

This is an example from the book I am reading: 1 (define (length items)

  • 0

This is an example from the book I am reading:

1    (define (length items)
2     (define (length-iter a count)
3       (if (null? a)
4           count
5           (length-iter (cdr a)(+ 1 count))))
6      (length-iter items 0))

What I am not understanding is how can length-iter know about count? The first time this
procedure is called with a list, it will in turn define another procedure with two argumenets, I get that much. But how does it know that a is the list items? It hasnt reached line 6 yet, where items is passed to length-iter as the argument a. Somehow though it already knows this and is able to make the computation. Any help in clarifying this a bit is appreciated!

  • 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:39:29+00:00Added an answer on June 11, 2026 at 9:39 am

    There are two parts in the length function:

    1. Definition of the inner function length-iter;
    2. Invocation of the inner function length-iter.

    In the invocation, i.e., line 6, you pass the original items list to the inner function as an argument. This is where the inner function gets called. Previously, you are just defining the function, not calling it:

    (length-iter items 0)
    

    Thus, items will be bound to a, and 0 to count. You can think of the inner function as a separate function:

    (define (length-iter a count)
      (if (null? a)
          count
          (length-iter (cdr a)(+ 1 count))))
    

    And then, think of your length function as if it just delegated all the work to the length-iter function:

    (define (length items)
      (length-iter items 0))
    

    That’s what’s being done in your function. The difference, is that the length-iter function is only known to length.

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

Sidebar

Related Questions

thank you for looking i got this example from my book but i cant
This is an example from a book, a bit modified. It seems like sessions
I'm reading a book to read and it covers this below example. somelist =
In a book I am currently reading, there is this excerpt: You can also
Came across this example in the book im reading and it didn't make sense
I was reading the example chapter from the book by Ayende and on the
These are example from a c# book that I am reading just having a
All examples are taken from the SICP Book: http://sicpinclojure.com/?q=sicp/1-3-3-procedures-general-methods This was motivated from the
In this example from The Ruby Programming Language (p.270), I'm confused why the instance_eval
In this example from the App Engine docs , why does the example declare

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.