built-ins: read: Port to Mes.

* gash/built-ins/read.scm (define-module): Import SRFI 14.
(right-pad): New procedure.
(main): Use it in place of a 'circular-list' trick.
This commit is contained in:
Timothy Sample 2022-12-22 13:28:34 -06:00
parent 7d713e0435
commit 88dfac30c3
1 changed files with 8 additions and 1 deletions

View File

@ -23,6 +23,7 @@
#:use-module (gash environment) #:use-module (gash environment)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (srfi srfi-14)
#:use-module (srfi srfi-26)) #:use-module (srfi srfi-26))
;;; Commentary: ;;; Commentary:
@ -84,6 +85,12 @@ field, while contiguous sequences of characters from the set
(reverse! (cons field acc))))))))) (reverse! (cons field acc)))))))))
(else '()))) (else '())))
(define (right-pad lst n)
(let ((m (length lst)))
(if (< m n)
(append lst (make-list (- n m) ""))
lst)))
(define (main . args) (define (main . args)
(match-let* (((vars . get-line) (match-let* (((vars . get-line)
(match args (match args
@ -102,7 +109,7 @@ field, while contiguous sequences of characters from the set
;; XXX: Verify that VAR is a valid variable name. ;; XXX: Verify that VAR is a valid variable name.
(setvar! var field)) (setvar! var field))
vars vars
(append fields (circular-list ""))) (right-pad fields (length vars)))
(if (eof-object? delimiter) (if (eof-object? delimiter)
EXIT_FAILURE EXIT_FAILURE
EXIT_SUCCESS))) EXIT_SUCCESS)))