Added (flatten lst) and guile module definition

master
Brady McDonough 5 years ago
parent d7156daf6d
commit c16fecddcb

@ -1,3 +1,21 @@
(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) (define (lp& p ls1 ls2)
(let loop ((ls1 ls1) (ls2 ls2)) (let loop ((ls1 ls1) (ls2 ls2))
(cond ((not (and (pair? ls1) (pair? ls2))) (cond ((not (and (pair? ls1) (pair? ls2)))
@ -7,8 +25,6 @@
(else '()) (else '())
))) )))
(define (ls& ls1 ls2) (define (l& ls1 ls2)
(cond ((eqv? ls1 ls2) ls1) (cond ((eqv? ls1 ls2) ls1)
(else (lp& eqv? ls1 ls2)))) (else (lp& eqv? ls1 ls2))))

Loading…
Cancel
Save