#!/usr/bin/guile !# ; depends on guile and sph-lib (use-modules (srfi srfi-1) (sph) (sph cli) (sph list) (sph io)) (define cli (cli-create #:options (q ( (union #:names #\u) (intersection #:names #\i) (difference #:names #\d) (complement #:names #\c) ((file-path ...)))) #:description "applies set operations to the lines of files. each file representing one set. writes the resulting lines to standard output")) (define (file-lines-set-operations operation file-paths) (let (operation-f (case operation ((union) union) ((intersection) intersection) ((difference) difference) ((complement) complement) (else #f))) (if operation-f (apply call-with-input-files (l files (fold (l (file result) (operation-f result (port->lines file))) (port->lines (first files)) (tail files))) file-paths) null))) (define (file-lines-set-operations-cli options) (let ( (operation (first-or-false (intersection (map first options) (q (union difference intersection complement))))) (file-paths (assq-ref options (q file-path)))) (if (and operation file-paths) (each display-line (file-lines-set-operations operation file-paths)) (cli (list "--help"))))) (file-lines-set-operations-cli (cli))