Email list hosting service & mailing list manager

vector->range issues Wolfgang Corcoran-Mathe (01 Sep 2020 19:21 UTC)
Re: vector->range issues Marc Nieper-Wißkirchen (01 Sep 2020 19:28 UTC)
Re: vector->range issues Wolfgang Corcoran-Mathe (01 Sep 2020 20:52 UTC)
Re: vector->range issues Marc Nieper-Wißkirchen (02 Sep 2020 05:48 UTC)
Re: vector->range issues Marc Nieper-Wißkirchen (02 Sep 2020 07:57 UTC)
string-range Marc Nieper-Wißkirchen (02 Sep 2020 13:14 UTC)
Re: string-range Wolfgang Corcoran-Mathe (02 Sep 2020 14:50 UTC)
Re: string-range Marc Nieper-Wißkirchen (02 Sep 2020 15:01 UTC)
Re: string-range Wolfgang Corcoran-Mathe (02 Sep 2020 15:56 UTC)
Re: string-range Marc Nieper-Wißkirchen (02 Sep 2020 15:58 UTC)
Re: string-range John Cowan (02 Sep 2020 21:12 UTC)
Re: string-range Wolfgang Corcoran-Mathe (02 Sep 2020 21:16 UTC)
Re: string-range Wolfgang Corcoran-Mathe (02 Sep 2020 21:25 UTC)
Re: vector->range issues Wolfgang Corcoran-Mathe (02 Sep 2020 14:46 UTC)

Re: string-range Marc Nieper-Wißkirchen 02 Sep 2020 15:01 UTC

Am Mi., 2. Sept. 2020 um 16:50 Uhr schrieb Wolfgang Corcoran-Mathe
<xxxxxx@sigwinch.xyz>:
>
> On 2020-09-02 15:14 +0200, Marc Nieper-Wißkirchen wrote:
> > In this spirit, I would also want to suggest
> >
> > (string-range STRING)
> >
> > a range constructor that takes a string and does the obvious thing. As
> > with vector-range, the argument mustn't be modified later.
> >
> > [snip]
> >
> > The nice thing is it is transparent for the user who just wants to
> > examine a string character-wise. He or she just has to work with
> > (string-range s) instead of s directly.
>
> Excellent points, I like it.  Added to my repository.

Excellent.

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).

Marc