简体   繁体   中英

Recursive search in Scheme

I'm currently stuck with the following problem :

I have a database of n elements and I want to do a recursive search so that I will get all the possible matches .

So , lets say , I get k matches for the first pattern . For every k matches I found I re-search the database with the next pattern and get the new association lists ....and so on . This is my problem , I cannot make a function that will give me all the results .

I really cannot get myself to think of a "plan" to attack this problem . I always wonder how to save my curent assoc-list and , at the same time , remove it when I get to the end.

Summary of my idea: If I have a database=db and need to match n patterns . I start with pattern 0 , get k assoc-list and I want to move forward to match pattern 1 , having in mind I have k assoc-lists from the previous,. I finish pattern 1 and get M assoc-list , for every m assoc-list I go forward ... In the end I either get a assoc-list of size n(number of patterns) or get false.

I really only want some ideas so I can get past this "brick wall". Please judge,stab,kill my idea , anything. Thank you.

I am not certain whether you wish to narrow or broaden your search based on subsequent searches. Here is pseudocode that broadens:

recursive_search (list_of_patterns)
  if is_empty(list_of_patterns)
    return empty_list
  pattern = pop_first(list_of_patterns)
  return query(pattern) + recursive_search(list_of_patterns)

EDIT to keep your pattern with the query as an alist... my scheme-foo is weak, but here goes:

(define query_alist (lambda x)(x . query-exec(x)))

(define r_query (lambda pattern__list)
  (cond
    ((null pattern_list) ())
    (else ((query_alist (first pattern_list) (r_query (rest pattern_list)))
  )
) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM