(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 "Generates an initial header list, listing the keys")) "[key|(key default)]..." "Reads alists from standard input and converts them to lists on standard output, by extracting the specified keys. If defaults are supplied, then that default is used if the key is missing, rather than raising an error.") (unless (> (length operands) 0) (usage)) (let* ((key-decls (map parse-code operands)) (keys (map (lambda (kd) (cond ((symbol? kd) kd) ((and (list? kd) (= (length kd) 2)) (car kd)) (else usage))) key-decls))) (when (assq 'header options) (data-write keys) (newline)) (for-each-input-datum (lambda (input) (data-write (map (lambda (kd) (cond ((symbol? kd) (alist-ref input kd (lambda () (error (sprintf "Invalid input: Missing value for ~a" kd) input)))) ((pair? kd) (alist-ref input (first kd) (lambda () (second kd)))))) key-decls)) (newline)))))