radix/utils.scm

23 lines
661 B
Scheme
Raw Normal View History

2023-08-04 11:31:31 +00:00
(define-module (radix utils)
#:use-module (srfi srfi-26)
#:export (associate-left
associate-right
flatmap))
(define-syntax-rule
(associate-left (key associations) ...)
`(,@(map (cut cons key <>) associations) ...))
(define-syntax-rule
(associate-right (association keys) ...)
`(,@(map (cut cons <> association) keys) ...))
(define (flatmap proc . args)
(if (null? (cdr args))
(map proc (car args))
(apply append
(map (lambda (x) (apply flatmap
(lambda arglist (apply proc x arglist))
(cdr args)))
(car args)))))