lexer: Avoid 'fold-right'.

* gash/lexer.scm (join-contiguous-strings): Use 'fold' and 'reverse'
instead of 'fold-right'.
This commit is contained in:
Timothy Sample 2023-02-08 11:45:32 -06:00
parent cfb4da73d0
commit 864e51250b
1 changed files with 10 additions and 7 deletions

View File

@ -165,13 +165,16 @@
(define (join-contiguous-strings lst) (define (join-contiguous-strings lst)
"Join all contiguous strings in @var{lst}." "Join all contiguous strings in @var{lst}."
(fold-right (lambda (x lst) (match lst
(let ((head (if (null? lst) #f (car lst)))) (() lst)
(if (and (string? x) (string? head)) ((head . rest)
(cons (string-append x head) (cdr lst)) (reverse
(cons x lst)))) (fold (lambda (x acc)
'() (if (and (string? x) (string? (car acc)))
lst)) (cons (string-append (car acc) x) (cdr acc))
(cons x acc)))
(list head)
rest)))))
(define-inlinable (next-char port) (define-inlinable (next-char port)
"Advance @var{port} by one character and return the lookahead "Advance @var{port} by one character and return the lookahead