From c2191a68f2855c03894d2267ff9853b1f02ba039 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 11 Apr 2015 22:26:44 -0400 Subject: utils: Add take-up-to. * haunt/utils.scm (take-up-to): New procedure. --- haunt/utils.scm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/haunt/utils.scm b/haunt/utils.scm index b9fe5e6..7eb1583 100644 --- a/haunt/utils.scm +++ b/haunt/utils.scm @@ -36,6 +36,7 @@ clean-directory mkdir-p string->date* + take-up-to)) (define* (flatten lst #:optional depth) "Return a list that recursively concatenates the sub-lists of LST, @@ -105,3 +106,13 @@ flattened." "Convert STR, a string in '~Y~m~d ~H:~M' format, into a SRFI-19 date object." (string->date str "~Y~m~d ~H:~M")) + +(define (take-up-to n lst) + "Return the first N elements of LST or an equivalent list if there +are fewer than N elements." + (if (zero? n) + '() + (match lst + (() '()) + ((head . tail) + (cons head (take-up-to (1- n) tail)))))) -- cgit v1.2.3