Re: using a character as argument to string-append!/string-append-linear! Per Bothner (18 Apr 2020 20:40 UTC)

Re: using a character as argument to string-append!/string-append-linear! Per Bothner 18 Apr 2020 20:39 UTC

On 4/18/20 1:13 PM, John Cowan wrote:
>        I think it would be possible (and probably useful) to design a Scheme
>     where character is a sub-type of string what remaining very compatible with
>     traditional Scheme, except that (equal? "X" \X).
>
>
> That works fine for polymorphic arguments, but not so much for returns.  Does string-ref still return a character?  Presumably.  So you end up with a SRFI 135 situation, where almost all procedures accept either strings or texts, but where the result is always a text (with the obvious exception of text->string).

I don't understand the problem.  In such hypothetical Scheme variant, all characters are strings
but not all strings are characters.  So string-ref returns a character - and thus also a string.
A procedure that accepts a string argument would also accept a character.

In Java notation:

    public interface String { ... }
    public interface Character extends String { ... }
    public static Character stringRef(String str, int index) { ... }
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/