From d539ba9d520d73d59ca1c87fd90dbd4b8c358f44 Mon Sep 17 00:00:00 2001 From: Cristian Esquivias Date: Tue, 12 Aug 2014 21:41:26 -0700 Subject: [PATCH] Added contracts --- rash.rkt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/rash.rkt b/rash.rkt index 7da0149..6938585 100644 --- a/rash.rkt +++ b/rash.rkt @@ -1,14 +1,25 @@ #lang racket/base +(require racket/contract) (require racket/port) (require racket/string) -(provide start pipe) +(define (executable? bin) + (find-executable-path bin)) + +(define (executable-list? command) + (and (find-executable-path (car command)) + (foldl (λ (i j) (and i j)) #t (map string? (cdr command))))) + +(provide (contract-out + [start (->* (executable? (listof string?)) + (#:stdin (or/c #f file-stream-port?)) + void?)] + [pipe (-> (listof string?) (listof string?) + void?)])) (define (start command args #:stdin [stdin #f]) (define cmd (find-executable-path command)) - (unless cmd - (raise (string-append command ": command not found"))) (define-values (proc out in err) (apply subprocess (current-output-port)