Skip to content

Instantly share code, notes, and snippets.

@b4284
Last active September 16, 2018 05:08
Show Gist options
  • Save b4284/4717e851ed7867f97682f89472a6e769 to your computer and use it in GitHub Desktop.
Save b4284/4717e851ed7867f97682f89472a6e769 to your computer and use it in GitHub Desktop.
;; (positional-list-match '("11") '("12"))
;; => #f
;; (positional-list-match '("11") '("11" "12"))
;; => #t
;; (positional-list-match '(any "12") '("11" "12"))
;; => #t
;; (positional-list-match '(any any any any any) '(5 4 3 2))
;; => #f
;; (positional-list-match 'any '(5 4 3 2))
;; => #t
;; (positional-list-match 'any #f)
;; => #t
;; (positional-list-match 'any '())
;; => #t
;; (positional-list-match `(,(lambda (d) (> (string->number d) 0)) "12") '("11" "12"))
;; => #t
(define (positional-list-match f d)
(if (and (list? f)
(list? d))
(let A ((frl f) (drl d) (r #t))
(if r
(if (null? frl)
#t
(if (null? drl)
#f
(A (cdr frl) (cdr drl)
(positional-list-match (car frl) (car drl)))))
#f))
(cond
((eq? f 'any) #t)
((procedure? f) (f d))
(else
(equal? f d)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment