From c81eb6ede070691c6c518ed6aa479eca11437f6e Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 23 Mar 2008 13:25:56 +0000 Subject: [PATCH] add in-lines and some doc clarifications svn: r9072 --- collects/scheme/private/for.ss | 17 +++++++++++ .../scribblings/reference/sequences.scrbl | 28 +++++++++++++------ src/mzscheme/src/module.c | 7 +++++ 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/collects/scheme/private/for.ss b/collects/scheme/private/for.ss index 807bcd43b3..4a8d8a501c 100644 --- a/collects/scheme/private/for.ss +++ b/collects/scheme/private/for.ss @@ -30,6 +30,7 @@ (rename *in-bytes in-bytes) in-input-port-bytes in-input-port-chars + in-lines in-hash-table in-hash-table-keys in-hash-table-values @@ -431,6 +432,22 @@ (lambda (x) (not (eof-object? x))) (lambda (x v) #t))))) + (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)) + (lambda (v) v) + v + (lambda (v) #t) + (lambda (x) (not (eof-object? x))) + (lambda (x v) #t))))])) + (define (in-hash-table ht) (unless (hash-table? ht) (raise-type-error 'in-hash-table "hash-table" ht)) (make-do-sequence (lambda () (:hash-table-gen ht cons (lambda (p) (values (car p) (cdr p))))))) diff --git a/collects/scribblings/reference/sequences.scrbl b/collects/scribblings/reference/sequences.scrbl index a8ec6b2b0c..b6f77e2304 100644 --- a/collects/scribblings/reference/sequences.scrbl +++ b/collects/scribblings/reference/sequences.scrbl @@ -89,12 +89,21 @@ Returns a sequence equivalent to @scheme[str]. Returns a sequence equivalent to @scheme[bstr]. @speed[in-bytes "byte string"]} -@defproc[(in-input-port-bytes [inp input-port?]) sequence?]{ -Returns a sequence equivalent to @scheme[inp].} +@defproc[(in-input-port-bytes [in input-port?]) sequence?]{ +Returns a sequence equivalent to @scheme[in].} -@defproc[(in-input-port-chars [inp input-port?]) sequence?]{ Returns a -sequence whose elements are read as characters form @scheme[inp] (as -opposed to using @scheme[inp] directly as a sequence to get bytes).} +@defproc[(in-input-port-chars [in input-port?]) sequence?]{ Returns a +sequence whose elements are read as characters form @scheme[in] (as +opposed to using @scheme[in] directly as a sequence to get bytes).} + +@defproc[(in-lines [in input-port? (current-input-port)] + [mode (one-of 'linefeed 'return 'return-linefeed 'any 'any-one) 'any]) + sequence?]{ + +Returns a sequence whose elements are the result of @scheme[(read-line +in mode)] until an end-of-line is encountered. Note that the default +mode is @scheme['any], whereas the default mode of @scheme[read-line] +is @scheme['linefeed].} @defproc[(in-hash-table [ht hash-table?]) sequence?]{ Returns a sequence equivalent to @scheme[ht].} @@ -153,8 +162,7 @@ The @scheme[thunk] results define the generated elements as follows: @itemize{ @item{The first result is a @scheme[_pos->element] procedure that takes - the current position and returns the value(s) for the current element. - It is called only once per position.} + the current position and returns the value(s) for the current element.} @item{The second result is a @scheme[_next-pos] procedure that takes the current position and returns the next position.} @@ -176,7 +184,11 @@ The @scheme[thunk] results define the generated elements as follows: } -} +Each of the procedures listed above is called only once per position. +Among the last three procedures, as soon as one of the procedures +returns @scheme[#f], the sequence ends, and none are call +again. Typically, one of the functions determines the end condition, +and the other two functions always return @scheme[#t].} @section{Sequence Generators} diff --git a/src/mzscheme/src/module.c b/src/mzscheme/src/module.c index ea3afaa593..0604083b89 100644 --- a/src/mzscheme/src/module.c +++ b/src/mzscheme/src/module.c @@ -1037,6 +1037,13 @@ static Scheme_Object *_dynamic_require(int argc, Scheme_Object *argv[], errname, name, srcm->modname); } + + if (!menv || !menv->toplevel) { + scheme_raise_exn(MZEXN_FAIL_CONTRACT, + "%s: module initialization failed: %V", + errname, + srcm->modname); + } b = scheme_bucket_from_table(menv->toplevel, (const char *)srcname);