From 864e51250b3ab6200b84dbf95d009db4cb9bc773 Mon Sep 17 00:00:00 2001 From: Timothy Sample Date: Wed, 8 Feb 2023 11:45:32 -0600 Subject: [PATCH] lexer: Avoid 'fold-right'. * gash/lexer.scm (join-contiguous-strings): Use 'fold' and 'reverse' instead of 'fold-right'. --- gash/lexer.scm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/gash/lexer.scm b/gash/lexer.scm index 4eaa2e2..bbafb89 100644 --- a/gash/lexer.scm +++ b/gash/lexer.scm @@ -165,13 +165,16 @@ (define (join-contiguous-strings lst) "Join all contiguous strings in @var{lst}." - (fold-right (lambda (x lst) - (let ((head (if (null? lst) #f (car lst)))) - (if (and (string? x) (string? head)) - (cons (string-append x head) (cdr lst)) - (cons x lst)))) - '() - lst)) + (match lst + (() lst) + ((head . rest) + (reverse + (fold (lambda (x acc) + (if (and (string? x) (string? (car acc))) + (cons (string-append (car acc) x) (cdr acc)) + (cons x acc))) + (list head) + rest))))) (define-inlinable (next-char port) "Advance @var{port} by one character and return the lookahead