diff options
author | David Thompson <dthompson2@worcester.edu> | 2015-04-11 22:26:44 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2015-04-11 22:33:54 -0400 |
commit | c2191a68f2855c03894d2267ff9853b1f02ba039 (patch) | |
tree | e129c6ef63a3ffdb9ca94d61713dce5d2320c99e | |
parent | 35bb74497dc7854feffa1e5d373e1f713da6a565 (diff) |
utils: Add take-up-to.
* haunt/utils.scm (take-up-to): New procedure.
-rw-r--r-- | haunt/utils.scm | 11 |
1 files changed, 11 insertions, 0 deletions
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)))))) |