Email list hosting service & mailing list manager


string-replicate Per Bothner 16 Mar 2017 01:15 UTC

I implemented string-replicate (in the "invoke" branch of Kawa),
along with a few tests.  Some question occurred to me:

(1) SRFI-13 calls this procedure xsubstring.  Perhaps we should just stick with that
name, for compatibility and conciseness.  But see (2).

(2) In SRFI-13 the default for the 'to' parameter is from+(end-start)),
rather than the current draft's (string-length string).  The latter
doesn't really make sense - it should at least be (end-start).

Either of the following seem useful as a default for 'to':
(a) from+(end-start)) means the default is that the length
of the result matches (the selected substring of) the argument
which makes it useful for 'rotate' operations.  (Though is
there much of a use for rotating strings?)  Plus this is
compatible with SRFI-13.

(b) (end-start) is convenient alias for string-drop.
However, if we already have string-drop, so this isn't all
that useful either.

I'm leaning towards (a), mainly for compatibility with SRFI-13,
and especially if we use the name xsubstring.

(3) A possibly useful extension, in the cases where to < from.

If to < from && to <= 0
then add (end-start) to 'to'.  This allows using negative indexes
to count from the end:
   (xsubstring str 1 -1) ;; strip 1st *and* last character
   (xsubstring str 2 0) ;; same as (string-drop str 2)
This generalizes the already-defined:
   (xsubstring str -10 -2) ;; last 8 characters of str
I.e. a negative index counts from the end. We support either
both indexes negative, or start non-negative and end negative,
or start positive and end zero.

Comments?
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/