added error checking for the reader, some shuffling

svn: r16471
This commit is contained in:
Eli Barzilay 2009-10-30 08:24:57 +00:00
parent 55506e6ecf
commit 87a5092c82

View File

@ -486,32 +486,40 @@
void))))
(define in-lines
(case-lambda
[() (in-lines (current-input-port))]
[(v) (in-lines v 'any)]
[(v mode)
(unless (input-port? v) (raise-type-error 'in-lines "input-port" v))
(unless (memq mode '(linefeed return return-linefeed any any-one))
(raise-type-error 'in-lines "('linefeed, 'return, 'return-linefeed, 'any, or 'any-one)" mode))
(make-do-sequence (lambda ()
(values (lambda (v) (read-line v mode))
values
v
void
(let ([mk (lambda (p m)
(make-do-sequence
(lambda ()
(values (lambda (p) (read-line p m))
values p void
(lambda (x) (not (eof-object? x)))
void)))]))
void))))])
(case-lambda
[() (in-lines (current-input-port) 'any)]
[(p) (in-lines p 'any)]
[(p mode)
(unless (input-port? p) (raise-type-error 'in-lines "input-port" p))
(unless (memq mode '(linefeed return return-linefeed any any-one))
(raise-type-error
'in-lines
"'linefeed, 'return, 'return-linefeed, 'any, or 'any-one"
mode))
(mk p mode)])))
(define in-port
(case-lambda
[() (in-port read (current-input-port))]
[(r) (in-port r (current-input-port))]
[(r p)
(unless (input-port? p) (raise-type-error 'in-port "input-port" p))
(let ([mk (lambda (p r)
(make-do-sequence
(lambda ()
(values r values p void
(lambda (x) (not (eof-object? x)))
void)))]))
void))))])
(case-lambda
[() (mk (current-input-port) read)]
[(r) (mk (current-input-port) r)]
[(r p)
(unless (and (procedure? r) (procedure-arity-includes? r 1))
(raise-type-error 'in->port "procedure (arity 1)" r))
(unless (input-port? p) (raise-type-error 'in-port "input-port" p))
(mk p r)])))
(define (in-hash ht)
(unless (hash? ht) (raise-type-error 'in-hash "hash" ht))