Module: streams-internals Synopsis: Basic definitions for streams Author: Scott McKay, Marc Ferguson, Eliot Miranda Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND /// Stream position type //--- This would be a subclass of , if it existed define open abstract class () end class ; //---*** Should be 'type-union(, )' define constant = ; /// Conditions define sealed class () constant slot stream-error-requested-position, required-init-keyword: position:; constant slot stream-error-size-of-stream, required-init-keyword: size:; end class ; define class () end class; define class () end class; define class () end class; /// End-of-stream handling utilities define function end-of-stream-value (stream :: , value) if (supplied?(value)) value else signal(make(, stream: stream)) end end function end-of-stream-value; define function stream-limit-or-error (stream :: ) => (limit :: ) stream-limit(stream) | error("Stream %= has no well-defined limit", stream) end function stream-limit-or-error; /// Direction checking utilities define function ensure-readable (stream :: ) => () unless (readable?(stream)) // Not readable, so the error is either that it's closed or write-only if (closed?(stream)) error(make(, stream: stream, format-string: "Can't read from closed stream")); elseif (write-only?(stream)) error(make(, stream: stream, format-string: "Can't read from write-only stream")); else error("Stream %= not readable, don't know why", stream); end if; end unless; end function ensure-readable; define function ensure-writable (stream :: ) => () unless (writable?(stream)) // Not writable, so the error is either that it's closed or write-only if (closed?(stream)) error(make(, stream: stream, format-string: "Can't write to closed stream")); elseif (read-only?(stream)) error(make(, stream: stream, format-string: "Can't write to read-only stream")); else error("Stream %= not writable, don't know why", stream); end if; end unless; end function ensure-writable;