+1 to Jim Rees' comments about using higher-level APIs
where applicable.  String ports and string-map/fold are
perfect for iterating.  However, for certain types of algorithms
you really do want a fast cursor-like API - notably the
SRFI 115 (regexp) reference implementation uses Chibi
string-cursors.

On Wed, Jul 2, 2014 at 6:26 AM, Per Bothner <[email protected]> wrote:

> I'm working on improving Kawa's Unicode support to
> be spec-compliant:
>
> https://sourceware.org/ml/kawa/2014-q2/msg00077.html
>
> I have two related questions/issues:
>
> (1) The Chibi "cursor" API for fast O(1) string access seems
> reasonable:
>
> https://code.google.com/p/chibi-scheme/source/browse/doc/chibi.scrbl
>
> However, there are no functions for string mutation - i.e. the
> replacement for string-set!.  Anyone implemented or designed such?
>

I tend to discourage string mutation, and once you're using
it there's not much advantage to cursors over string-set!
(better average cost maybe, but same worst-case).  But for
a consistent API it makes sense to have this.  I think
string-cursor-set! makes sense.

(2) Once we have variable-length characters (UTF-8 or UTF-16)
> stored in a buffer, then any string that you can mutate with
> string-set! inherently becomes a variable-length string.


Depending on implementation.  Since some implementations
will use UCS-32 internally and will want to take advantage of
this.  We should not make assumptions in the string-cursor API
so that it's both efficient and portable.  In particular, since it's
meant to be low-level, we should not require the cursors be a
disjoint type, and we may want to allow the accessors to be
macros.

So we might as well let the Scheme programmer make use of that.
> I'm thinking of adding a general function:
>
> (string-replace! to to-start to-end from [from-start [from-end]])
>

This is also very useful, but I think belongs to a higher
level data structure with better efficiency guarantees than
"may reallocate the whole string."  Definitely check out
Taylor Campbell's text API:

  http://mumble.net/~campbell/proposals/new-text.txt

-- 
Alex
_______________________________________________
Scheme-reports mailing list
[email protected]
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports

Reply via email to