(use magic-pipes) (use args) (use alist-lib) (use srfi-1) (receive (options operands before-exprs after-exprs usage) (parse-mp-args (command-line-arguments) (list (args:make-option (H header) #:none "Uses the first input list as the key list, rather than the command line.")) "key..." "Reads lists from standard input and converts them to alists on standard output, by labelling the elements of the input lists with the specified keys. The length of the input lists and the list of keys must match, or an error is thrown.") (if (assq 'header options) ;; -H mode, expect zero args (unless (= (length operands) 0) (usage)) ;; not -H mode, need at least one arg (unless (> (length operands) 0) (usage))) (let* ((keys (if (assq 'header options) (map (lambda (key) (string->symbol (->string key))) (data-read)) ;; First line (map parse-code operands)))) ;; Command line args (for-each-input-datum (lambda (input) (unless (= (length keys) (length input)) (error "An input record has the wrong number of entries" input)) (data-write (map (lambda (key element) (cons key element)) keys input)) (newline)))))