How do we verify in scheme with the do cicle, if an element of the first list is in the second?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The do loop in racket has an interesting structure:
The documentation for r5rs provides an example:
That statement returns 25, the sum of the elements of the loop. The
xin the do loop is initialized to thexin the let, and then iteratively set to thecdrof itself each time through the loop.sumis initialized to 0, and accumulates the value of thecarofxeach 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):
Instead of initializing and adding the value
sum, Iorintofound. Also, I preferfirstandrestovercarandcdrand define them myself when they don’t exist. The way this function works should follow from the explanation of the example.Gives #f, as expected. Similarly:
Gives #t.
Are you able to generalize finding a specific element in a list with a do loop into your specific question?