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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:28:45+00:00 2026-05-22T17:28:45+00:00

How do we verify in scheme with the do cicle, if an element of

  • 0

How do we verify in scheme with the do cicle, if an element of the first list is in the second?

  • 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-05-22T17:28:45+00:00Added an answer on May 22, 2026 at 5:28 pm

    The do loop in racket has an interesting structure:

    (do ([id init-expr step-expr-maybe] ...)
        (stop?-expr finish-expr ...)
      expr ...)
    

    The documentation for r5rs provides an example:

    (let ((x '(1 3 5 7 9)))
      (do ((x x (cdr x))
           (sum 0 (+ sum (car x))))
          ((null? x) sum)))
    

    That statement returns 25, the sum of the elements of the loop. The x in the do loop is initialized to the x in the let, and then iteratively set to the cdr of itself each time through the loop. sum is initialized to 0, and accumulates the value of the car of x each time through. The stopping condition is when the iteration variable is empty, and the return value is the sum.

    Ok, aside from the racket preference of square brackets, this looks good. There’s a do loop and a list. The loop does something over that list. We can use that to write a function that finds a specific atom in a list (using the racket brackets):

    (define (find5 lst)
      (do ([x lst (rest x)]
           [found #f (or found (eq? 5 (first x)))])
        ((null? x) found)))
    

    Instead of initializing and adding the value sum, I or into found. Also, I prefer first and rest over car and cdr and define them myself when they don’t exist. The way this function works should follow from the explanation of the example.

    (find5 '(1 2 3 4 6))
    

    Gives #f, as expected. Similarly:

    (find5 '(1 2 3 4 5 6))
    

    Gives #t.

    Are you able to generalize finding a specific element in a list with a do loop into your specific question?

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

Sidebar

Related Questions

I'm trying to verify if a schema matches the objects I'm initializing. Is there
I wanna verify a digitally signed xml against its schema definition while this schema
In order to verify the data coming from the Google Safe Browsing API ,
How can I verify a given xpath string is valid in C#/.NET? I'm not
I want to programmatically verify the status of an application to see if it
Is it possible to verify which source safe project is bound to my vs.net
I have to verify the signature on a file that may be as large
I want to verify if a computer is running .net 3.5 or 3.5 sp1,
How can I verify an X509 (or DER-formatted) certificate against the Java certificate store
What is the simplest most effective way to verify that your SQLite db is

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.