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)
"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