From fc8d00e2eb4d5bdb40cdc58ec70489273d39e04a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 30 Jan 2021 21:29:26 +0100 Subject: Move useful stuff to utils --- guile/starlet/utils.scm | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'guile/starlet/utils.scm') diff --git a/guile/starlet/utils.scm b/guile/starlet/utils.scm index be87321..049bd86 100644 --- a/guile/starlet/utils.scm +++ b/guile/starlet/utils.scm @@ -1,7 +1,13 @@ (define-module (starlet utils) + #:use-module (srfi srfi-1) #:export (return-unspecified print-hash-table - copy-hash-table)) + copy-hash-table + partial + in-range + mean + flatten-sublists + more-than-one)) (define (return-unspecified) @@ -21,3 +27,39 @@ (hash-set! new-ht key value)) ht) new-ht)) + + +(define (partial f second-val) + (lambda (first-val) + (f first-val second-val))) + + +(define (in-range a val1 val2) + (or + (and (>= a val1) + (<= a val2)) + (and (>= a val2) + (<= a val1)))) + + +(define (mean vals) + (/ (fold + 0 vals) + (length vals))) + + +(define (flatten-sublists l) + + (define (listify a) + (if (list? a) + a + (list a))) + + (fold (lambda (a prev) + (append prev (listify a))) + '() l)) + + +(define (more-than-one a) + (if (nil? a) + #f + (not (nil? (cdr a))))) -- cgit v1.2.3