Subject: Re: suggestion for FLEXI-STREAMS
From: Edi Weitz <[email-masked]>
To: Nathan Froyd <[email-masked]>
Date: Wed, 11 Jan 2006 00:31:53 +0100

Hi Nathan!

On Tue, 10 Jan 2006 16:32:11 -0600, Nathan Froyd <[email-masked]> wrote:

> First off, thanks so much for making FLEXI-STREAMS available!  It
> solves so many problems in one fell swoop.  I am using FLEXI-STREAMS
> in the next revision of my ARCHIVE library to provide access to the
> data stored in archive entries and it's working great.

Good... :)

> However, I'd like to write this function:
>
> (defun entry-stream (entry &key external-format)
>   "Return a stream connected to the data of ENTRY.  EXTERNAL-FORMAT is
> either a name for a FLEXI-STREAMS external format or a FLEXI-STREAMS
> external-format object."
>   (let ((stream (slot-value entry 'stream)))
>     (when external-format
>       (setf (flexi-streams:flexi-stream-external-format stream)
>             (typecase external-format
>               ;; unfortunately, EXTERNAL-FORMAT is not external in
>               ;; the FLEXI-STREAMS package...
>               (flexi-streams:external-format external-format)
>               (t (flexi-streams:make-external-format external-format)))))
>     stream))
>
> The intent is that the user can pass in previously constructed
> EXTERNAL-FORMAT objects to avoid creating a new EXTERNAL-FORMAT
> object each time the entry stream is requested.  Could
> EXTERNAL-FORMAT be exported from FLEXI-STREAMS to enable this?

Well, I could do that but I don't think it's necessary.

First of all you could write something like (untested)

  (typecase external-format
    ((or symbol list) (flexi-streams:make-external-format external-format))
    (t external-format))

but actually this is not necessary.  You can just write

  (setf (flexi-streams:flexi-stream-external-format stream)
        external-format)

and FLEXI-STREAMS should take care of the rest.  (In streams.lisp,
look at MAYBE-CONVERT-EXTERNAL-FORMAT and the two methods that use
it.)

Cheers,
Edi.