diff options
author | Arun Isaac | 2021-02-27 23:50:48 +0530 |
---|---|---|
committer | Arun Isaac | 2021-02-27 23:50:48 +0530 |
commit | c37a8e33f790b385ec1f913b062ad5b5f4bbe96e (patch) | |
tree | 5f19b5ff43b5c7f2c72d4a523a01b36064b0a965 /ccwl/ccwl.scm | |
parent | d475760dfbbc0a3bb2732a924b006e68f6dcc065 (diff) | |
download | ccwl-c37a8e33f790b385ec1f913b062ad5b5f4bbe96e.tar.gz ccwl-c37a8e33f790b385ec1f913b062ad5b5f4bbe96e.tar.lz ccwl-c37a8e33f790b385ec1f913b062ad5b5f4bbe96e.zip |
Add break-pair utility.
* ccwl/ccwl.scm (break-pair): New function.
* tests/ccwl.scm: New file.
* tests/ccwl.scm ("break-pair", "break-pair: check last elemet
handling"): New test cases.
Diffstat (limited to 'ccwl/ccwl.scm')
-rw-r--r-- | ccwl/ccwl.scm | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/ccwl/ccwl.scm b/ccwl/ccwl.scm index 1f69d41..0d261d6 100644 --- a/ccwl/ccwl.scm +++ b/ccwl/ccwl.scm @@ -80,6 +80,22 @@ variable." (parse-arguments tail (1+ position)))) (() '()))) +(define (break-pair pred lst) + "Return the longest initial prefix of LST that does not satisfy PRED, +and the remaining tail. PRED is a 2-arity predicate. For each element +under consideration, PRED is passed that element and the next. For the +last element of LST, PRED is passed that element alone." + (match lst + ((head next tail ...) + (if (not (pred head next)) + (let ((prefix tail (break-pair pred (cons next tail)))) + (values (cons head prefix) tail)) + (values (list) lst))) + ((last) + (if (not (pred last)) + (values lst (list)) + (values (list) lst))))) + (define (parse-command args) "Parse ARGS, a list of command line arguments and return two lists---the base command and the actual arguments." |