#! /bin/sh #| Hey Emacs, this is -*-scheme-*- code! #$Id$ exec mzscheme -u "$0" ${1+"$@"} |# #lang scheme (require "../prelude.ss") ; (string->string) -> string -> string -> # (define (interact-with f in out) (with-output-to-file out #:mode 'text #:exists 'replace (λ () (with-input-from-file in (λ () (let next-line ([line (read-line)]) (cond [(eof-object? line) (void)] [else (write-string (f line)) (newline) (next-line (read-line))]))) #:mode 'text)))) ; char -> boolean (define char-nonspace? (compose not char-whitespace?)) ; string -> string (define (first-word line) (list->string (take-while char-nonspace? (drop-while char-whitespace? (string->list line))))) ;; Program execution starts here (define (main) (define arguments (current-command-line-arguments)) (if (= (vector-length arguments) 2) (let ([in (vector-ref arguments 0)] [out (vector-ref arguments 1)]) (interact-with first-word in out)) (error "interact-with expects exactly 2 arguments : interact-with in-file-path out-file-path\n\tProvided : " arguments))) (main)