A. Helpers

General-purpose, custom functions that might be used in several sections, appear here 

;; Helper which aims to reduce code clutter by:
;; * Replacing the oft-used, '(display item) (newline)' combination
;; * Avoiding overuse of '(string-append)' for simple output tasks
(define (print item . rest)
  (let ((all-item (cons item rest)))
      (lambda (item) (display item) (display " "))      

;; ------------

;; Slightly modified version of '(qx)' from Chapter 4
(use-modules (ice-9 popen) (srfi srfi-1) (srfi srfi-13))

(define (drain-output port)
  (let loop ((chars '())
             (next (read-char port)))
    (if (eof-object? next)
        ; Modified to not return last 'line' with newline
        (list->string (reverse! (cdr chars)))
        (loop (cons next chars)
              (read-char port)))))

(define (qx pipeline)
  (let* ((pipe (open-input-pipe pipeline))
         (output (drain-output pipe)))
    (close-pipe pipe)

;; ------------