From 828f123cd881f031a30705d192f3531da8275e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?c=C3=A6l=C5=8Drum=20spect=C4=81tr=C4=ABx?= Date: Wed, 3 Dec 2025 01:41:14 +0100 Subject: [PATCH] Add string-split to common.scm --- common.scm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/common.scm b/common.scm index 094a23f..e2a75d4 100644 --- a/common.scm +++ b/common.scm @@ -1,6 +1,28 @@ +;; Shitty print for convenience (define (print . args) (display (apply string-append args)) (newline)) +;; Chicken command-line-arguments for no reason at all (define (command-line-arguments) (cdr (command-line))) + +;; Guile string-split +(define (string-split str delim?) + (let ((in (open-input-string str))) + (let loop ((acc '()) + (out (open-output-string))) + (let ((c (read-char in))) + (cond + ((eof-object? c) + (reverse (cons (get-output-string out) acc))) + ((delim? c) + (loop (cons (get-output-string out) acc) + (open-output-string))) + (else + (write-char c out) + (loop acc out))))))) + +;; Reverse for-each, for convenience +(define (xfor-each1 lst fn) + (for-each fn lst))