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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:33:18+00:00 2026-05-13T22:33:18+00:00

I have the following items (define itemslist (list ‘a1 ‘b2 ‘c3 (list ‘z1 ‘z2)

  • 0

I have the following items

(define itemslist
  (list 'a1 'b2 'c3 (list 'z1 'z2) 'd5 'e6))

My method to find items is below

(define find-item
  (lambda (item itemslist)
    (cond ((null? itemslist) #f)
          ((list? (car itemslist))
            (cond ((null? itemslist) #f)
                  (else (find-item item (car itemslist)))))
          ((equal? stn (car itemslist)) (display "found"))
          (else (find-stn stn (cdr itemslist)))
          )
    )
  )

With my method above I can find a1, b2, c3, z1, z2. But when I want to find d5 onwards, it returns nothing. It seems to have skip the stack. Btw, I am just starting to learn Scheme so simple explanation would be better.

One more qns, how about if I have this

(list 'a1 'b2 'c3 (list 'z1 (list 'y1 'y2) 'z2) 'd5 'e6)

does this works as well? Thanks!

  • 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-13T22:33:18+00:00Added an answer on May 13, 2026 at 10:33 pm

    Yes, you skip lists.
    Example:

    '(1 '(2 3) 4)
    

    If (list? '(2 3)) is true, the else part (outer cond) wont be evaluated so 4 is skipped.
    So, either you place the else part inside list? block or you redesign your code.

    If the itemlist is a list/pair you can pass it right away in a recursive call so
    you can avoid writing code like (car itemslist) inside predicates thus make the code simple.

    Here is a redesigned (simplified) version:

    (define (find-item item l)
      (cond ((equal? item l) #t)
            ((pair? l) (or (find-item item (car l)) (find-item item (cdr l))))
            (else #f)))
    

    Tip: you can also can write lists with '(...) notation instead of (list ...), ie

    (find-item 'z2 '('a1 'b2 'c3 '('z1 '('y1 'y2) 'z2) 'd5 'e6))  
    #t  
    (find-item 'e6 '('a1 'b2 'c3 '('z1 '('y1 'y2) 'z2) 'd5 'e6))  
    #t
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following list of tuples: items = [ ('john jones', ['Director', 'Screenwriter',
I have the following code: foreach (ListItem item in check.Items) { if (item.Selected) {
I have defined the following: public ICollection<Item> Items { get; set; } When I
I have a following items displayed on an asp.net page (C#). 1 Welcome 2
I have the following three items displayed side by side: <div class=page-header> <h1 style=line-height:0>Title</h1>
I have the following code: NSLog(@items: %d, [items count]); NSLog(@allObjects: %d, [self.allObjects count]); [self.allObjects
I have a listbox in C# with the following items: Package1 Package2 Package3 Package4
I have a following table using MVC that shows number of items the user
I have the following linq expression pulling all data from my database: var items
I have the following jQuery $.ajax({ type: GET, url: http://f.cl.ly/items/0i1V1L1k2F440L1m2Y0G/pointdata.xml, dataType: xml, success: parseXml

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.