alist map/filter/for-each

This commit is contained in:
Dane Johnson 2025-02-28 14:26:08 -06:00
parent 75224b9100
commit a2c651c134
2 changed files with 19 additions and 0 deletions

15
d-.scm
View File

@ -15,6 +15,9 @@
upply upply
conjoin conjoin
distinct? distinct?
amap
afilter
afor-each
generator generator
macro-expand macro-expand
amb amb
@ -103,6 +106,18 @@
(and (not (any (lambda (x) (equal? (car a) x)) (cdr a))) (and (not (any (lambda (x) (equal? (car a) x)) (cdr a)))
(apply distinct? (cdr a))))) (apply distinct? (cdr a)))))
(define (amap f l)
"Same as (map f l) but passes car and cdr to the function"
(map (lambda (kons) (f (car kons) (cdr cons))) l))
(define (afilter f l)
"Same as (filter f l) but passes car and cdr to the function"
(filter (lambda (kons) (f (car kons) (cdr cons))) l))
(define (afor-each f l)
"Same as (for-each f l) but passes car and cdr to the function"
(for-each (lambda (kons) (f (car kons) (cdr cons))) l))
;; Shamelessly ripped from https://wingolog.org/archives/2013/02/25/on-generators ;; Shamelessly ripped from https://wingolog.org/archives/2013/02/25/on-generators
(define (make-generator f) (define (make-generator f)
(define tag (make-prompt-tag)) (define tag (make-prompt-tag))

View File

@ -80,6 +80,10 @@
(define-test "vacuous" (define-test "vacuous"
(assert-equal #t ((conjoin) '(some donkus))))) (assert-equal #t ((conjoin) '(some donkus)))))
(define-test-suite "map"
(define-test "test"
(assert-equal )))
(define-test-suite "generator" (define-test-suite "generator"
(define-test "test" (define-test "test"
(define number-generator (define number-generator