Thanks Taylan!

This seems to imply to me that concatenation is O(n), however.  Although yes, the SRFI-135 text does say that other operations are amortized linear (i.e. amortized O(n)).

I was more expecting O(log n) random access, O(log n) concatenation, but I suppose the O(1) random access and O(n) concatenation is fine.

On Sat, Jun 11, 2016 at 9:19 AM, Taylan Ulrich Bayırlı/Kammer <xxxxxx@gmail.com> wrote:
Alan Manuel Gloria <xxxxxx@gmail.com> writes:

> Thanks! My understanding of functional immutable sequence structures
> led me to think that all such would be O(log n) for an indexing
> operation. I'm thus quite curious on O(1) indexing on an immutable
> text.

As far as I understood:

Long story short, the text is cut into fixed-width substrings, say of
length 80, so text-ref is implemented principally like:

     (define (text-ref text idx)
       (let-values (((part-idx idx-within-part) (floor/ idx 80)))
         (let ((part (vector-ref (%text-parts part-idx) part-idx)))
           (string-ref part idx-within-part))))

Thus O(n) becomes O(1).

Taylan