(define-module (tk listlogic) #:export (flatten lp& l& ) #:duplicates (warn-override-core warn )) (define (flatten-helper lst acc stk) (cond ((null? lst) (if (null? stk) (reverse acc) (flatten-helper (car stk) acc (cdr stk)))) ((pair? (car lst)) (flatten-helper (car lst) acc (cons (cdr lst) stk))) (else (flatten-helper (cdr lst) (cons (car lst) acc) stk)))) (define (flatten lst) (flatten-helper lst '() '())) (define (lp& p ls1 ls2) (let loop ((ls1 ls1) (ls2 ls2)) (cond ((not (and (pair? ls1) (pair? ls2))) '()) ((p (car ls1) (car ls2)) (cons (car ls1) (loop (cdr ls1) (cdr ls2)))) (else '()) ))) (define (l& ls1 ls2) (cond ((eqv? ls1 ls2) ls1) (else (lp& eqv? ls1 ls2))))