Running queries against a list of lists in Scheme

跟風遠走 提交于 2019-12-02 08:06:17

How about running a filter routine across the list, and using a lambda object initialized with your query information that will then be applied to the list until it finds a match.

So for instance, you would have a lamda that would look something like

(define (filter-object query)
    (define (query-function list-input)
        ;;do something here for query function that will take the initialized
        ;;query and match it against the list-input to see if there's a match
        ;;it should return #t or #f
    )

    ;;the return of the filter-object is the query function
    query_function) 

;;my-filter-function is initialized with a specific query
(define my-filter-function (filter-object '(a for what)))

Now with the filter-object initialized, run a filter across your list

(define (filter filter-function list-of-lists)
    (cond ((eq? list-of-lists '()) '())
          ((filter-function (car list-of-lists))
           (cons (car list-of-lists)
              (filter filter-function (cdr list-of-lists)))
          (else (filter filter-function (cdr list-of-lists))))

(filter my-filter-function my-list)

This should return a one-element list of the matches (providing you aren't placing more than one copy in your list set.

Hope this helps,

Jason

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!