DEFINITION Strings;
PROCEDURE Length (s: ARRAY OF CHAR): INTEGER;
PROCEDURE Insert (source: ARRAY OF CHAR; pos: INTEGER; VAR dest: ARRAY OF CHAR);
PROCEDURE Append (extra: ARRAY OF CHAR; VAR dest: ARRAY OF CHAR);
PROCEDURE Delete (VAR s: ARRAY OF CHAR; pos, n: INTEGER);
PROCEDURE Replace (source: ARRAY OF CHAR; pos: INTEGER; VAR dest: ARRAY OF CHAR);
PROCEDURE Extract (source: ARRAY OF CHAR; pos, n: INTEGER; VAR dest: ARRAY OF CHAR);
PROCEDURE Pos (pattern, s: ARRAY OF CHAR; pos: INTEGER): INTEGER;
PROCEDURE Cap (VAR s: ARRAY OF CHAR);
END Strings
As is hinted at in the documentation of Strings both Insert and Delete can be implemented trivially in terms of procedure Replace. So maybe it is enough to stress this in the documentation by printing these words in bold typeface:
Hint: if len = 0 then rep is inserted in s at position pos. If LEN(rep$) = 0 then the stretch [pos, MIN(pos+len, LEN(s$))) is deleted from s.
HansKlaver wrote: ↑Mon Mar 28, 2022 7:50 pm
As is hinted at in the documentation of Strings both Insert and Delete can be implemented trivially in terms of procedure Replace. So maybe it is enough to stress this in the documentation by printing these words in bold typeface:
Hint: if len = 0 then rep is inserted in s at position pos. If LEN(rep$) = 0 then the stretch [pos, MIN(pos+len, LEN(s$))) is deleted from s.
Thanks a lot, there is also in-code comment about this extra semantics. I agree, this should be highlighted in documentation.