From 88dfac30c3161717a3bd9d6aac602ae411bd82d8 Mon Sep 17 00:00:00 2001 From: Timothy Sample Date: Thu, 22 Dec 2022 13:28:34 -0600 Subject: [PATCH] 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. --- gash/built-ins/read.scm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gash/built-ins/read.scm b/gash/built-ins/read.scm index 5e916ac..8be2826 100644 --- a/gash/built-ins/read.scm +++ b/gash/built-ins/read.scm @@ -23,6 +23,7 @@ #:use-module (gash environment) #:use-module (ice-9 match) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-14) #:use-module (srfi srfi-26)) ;;; Commentary: @@ -84,6 +85,12 @@ field, while contiguous sequences of characters from the set (reverse! (cons field acc))))))))) (else '()))) +(define (right-pad lst n) + (let ((m (length lst))) + (if (< m n) + (append lst (make-list (- n m) "")) + lst))) + (define (main . args) (match-let* (((vars . get-line) (match args @@ -102,7 +109,7 @@ field, while contiguous sequences of characters from the set ;; XXX: Verify that VAR is a valid variable name. (setvar! var field)) vars - (append fields (circular-list ""))) + (right-pad fields (length vars))) (if (eof-object? delimiter) EXIT_FAILURE EXIT_SUCCESS)))