Better types #15

Merged
alex-eg merged 27 commits from better-types into main 2025-10-30 16:05:44 +01:00
3 changed files with 43 additions and 1 deletions
Showing only changes of commit cca63fb4df - Show all commits

View File

@@ -9,6 +9,7 @@
(include "basic.scm") (include "basic.scm")
(include "semen.scm") (include "semen.scm")
(include "utils.scm")
;;; Should be the last in the test suite ;;; Should be the last in the test suite
(test-exit) (test-exit)

22
tests/utils.scm Normal file
View File

@@ -0,0 +1,22 @@
(test-group "utils"
(test
'((1) (2) (3))
(list-split '(1 * 2 * 3) '*))
(test
'((1 2 3))
(list-split '(1 2 3) '*))
(test
'(() (1) (2) (3) ())
(list-split '(* 1 * 2 * 3 *) '*))
(test
'((const) (const struct something))
(list-split '(const * const struct something) '*))
(test
'(1 * 2 * 3)
(list-join '(1 2 3) '*))
)

View File

@@ -4,7 +4,8 @@
(import (import
(chicken pathname) (chicken pathname)
(chicken process-context)) (chicken process-context)
srfi-1)
(define (get-env-var name) (define (get-env-var name)
(get-environment-variable name)) (get-environment-variable name))
@@ -17,3 +18,21 @@
(make-absolute-pathname (make-absolute-pathname
(current-directory) (current-directory)
(pathname-directory file)))))) (pathname-directory file))))))
(define (list-split src-list split-elt)
;; split '(1 2 / 3 4 / 5 6) by '/ -> '((1 2) (3 4) (5 6))
(fold (lambda (elt acc)
(if (eq? elt split-elt)
(append acc (list (list)))
(append (drop-right acc 1)
(list (append (last acc) (list elt))))))
(list (list))
src-list))
(define (list-join lists join-by)
(drop-right
(fold (lambda (elt acc)
(append acc (list elt) (list join-by)))
(list)
lists)
1))