From 1d3d292fa7f79d9b276df5c30d51229cf841690b Mon Sep 17 00:00:00 2001 From: SouthFox Date: Fri, 1 Nov 2024 13:51:34 +0800 Subject: [PATCH] feat: update sub-string-list Signed-off-by: SouthFox --- game.scm | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/game.scm b/game.scm index 8972373..e1e7c8d 100644 --- a/game.scm +++ b/game.scm @@ -166,24 +166,28 @@ `(pre ,(string-join ink-script "\n"))) -(define (sub-string-list string-list start len part) - (if (string? (car string-list)) - (if (> (string-length (car string-list)) start) - (append part - (list (substring (car string-list) 0 start) - (substring (car string-list) start (+ start len))) - (if (= (+ start len) (string-length (car string-list))) - '() - (list (substring (car string-list) (+ start len) (string-length (car string-list))))) - (cdr string-list)) - (sub-string-list (cdr string-list) - (- start (string-length (car string-list))) - len - (append part (list (car string-list))))) - (sub-string-list (cdr string-list) - (- start (string-length (car (last-pair (car string-list))))) - len - (append part (list (car string-list)))))) +(define (sub-string-list string-list start len) + (define (sub-string-list-iter string-list start len part) + (if (string? (car string-list)) + (if (> (string-length (car string-list)) start) + (append part + (if (= start 0 ) + '() + (substring (car string-list) 0 start)) + (list (substring (car string-list) start (+ start len))) + (if (= (+ start len) (string-length (car string-list))) + '() + (list (substring (car string-list) (+ start len) (string-length (car string-list))))) + (cdr string-list)) + (sub-string-list-iter (cdr string-list) + (- start (string-length (car string-list))) + len + (append part (list (car string-list))))) + (sub-string-list-iter (cdr string-list) + (- start (string-length (car (last-pair (car string-list))))) + len + (append part (list (car string-list)))))) + (sub-string-list-iter string-list start len '())) ;; Main (set! *template* template-task)