Re: string-range Wolfgang Corcoran-Mathe 02 Sep 2020 15:56 UTC

On 2020-09-02 17:01 +0200, Marc Nieper-Wißkirchen wrote:
> Would (range->string RANGE) also make sense then? It would be an error
> if not every element of the range were a character.
>
> (define (range->string range)
>   (let ((s (make-string (range-length range))))
>     (range-fold (lambda (i ch) (string-set! s i ch) (+ 1 i)) 0 range)
>     s))
>
> (No assume necessary because string-set! should have a type test for CH.)
>
> In case, an implementation (with O(1) access to random string
> elements) implements string ranges in a special way, the restriction
> that the result of range->string mustn't be modified should be added
> (as we have it for range->vector).

For completeness, yes, this should be added, since vector-range has
range->vector, etc.  Hopefully this will be it for additional
conversions and constructors.

--
Wolfgang Corcoran-Mathe  <xxxxxx@sigwinch.xyz>

"Some folks think Postmodernism means little more than the Empowerment
of the Vulgar.  Some folks think the same about Perl." --Larry Wall