On Sat, Feb 7, 2015 at 10:51 PM, John Cowan <[email protected]> wrote:
> Alex Shinn scripsit:
>
> > I still don't understand what is meant by leaky, or why
> > this closure is any way preferable to a single object.
>
> Because it lessens the amount of ambient authority. In SRFI 6,
> I can't give you the authority to extract objects from the output port
> without also giving you the authority to write to it.
>
OK.
> > The problem with a single global get-output-string
> > procedure is that it needs a way to get at the underlying
> > buffer associated with the string port, which you can't
> > do portably. The best you can do is, assuming you
> > have weak references, maintain a global weak hash
> > eqv? table mapping string port to buffer.
>
> Custom ports always involve closing over some sort of data structure,
> which can be a character sequence as well as anything else.
>
Somehow I've still failed to convey my point, so I'll just write code.
In R6RS the following is a rough but fully portable implementation
of output string ports:
(define (open-string-output-port)
(let ((buf '()))
(values
(make-custom-textual-output-port
""
(lambda (str start count)
(let ((ls (string->list (substring str start (+ start count)))))
(set! buf (append (reverse ls) buf))
(length ls)))
#f #f #f)
(lambda ()
(let ((res (list->string (reverse buf))))
(set! buf '())
res)))))
You can't implement SRFI 6 output string ports without
non-portable extensions.
[This was already discussed when we were voting on it.]
--
Alex
_______________________________________________
Scheme-reports mailing list
[email protected]
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports