string-set!(3scm)
π string-set!(3scm) π
okay bestie, welcome to the Schemer's Programmer's Manual β¨ β we're doing string-set! today and honestly? she's a little niche but she's iconic. let's get into it π
β¨ NAME β¨
string-set! β modify a string element π¦
π LIBRARY π
import her from one of these, girl:
(import (rnrs mutable-strings)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
π« SYNOPSIS π«
(string-set! string k char)
πΈ DESCRIPTION πΈ
so basically: this stores char in element k of string. simple as that, no cap π
- R6RS β implementors should make
string-ref(3scm) run in constant time, which lowkey means this procedure might also run in constant time. might. π - R7RS β yeah there's literally no requirement for this procedure to execute in constant time. it's giving "we don't promise anything" energy π
π«Ά RETURN VALUES π«Ά
- R6RS β returns unspecified values. plural! fancy π
- R7RS β returns an unspecified value. singular. humble.
π₯ EXAMPLES π₯
look at her go:
(define (f) (make-string 3 #\*))
(define (g) "***")
(string-set! (f) 0 #\?) => unspecified
(string-set! (g) 0 #\?) => unspecified
; should raise &assertion exception
ok so (f) gives you a fresh mutable string and slays, but (g) is a literal and that last one should raise an &assertion exception π that's the vibe check right there.
π APPLICATION USAGE π
ngl, this procedure is rarely used to modify existing strings. sometimes people use it to build up new strings, but the better option is often to use an output string created by open-string-output-port(3scm) β which has the benefit that the output length does not need to be known in advance. queen behavior honestly π like why pre-calculate when you can just vibe and let the port handle it π§
π COMPATIBILITY π
this procedure works the same everywhere. periodt. π― Whether a string literal is truly immutable depends on the implementation (but they should not be mutated either way) β so like, don't come for me if you get got π«
π ERRORS π
she can raise exceptions with the following condition types:
&assertion(R6RS) β the wrong number of arguments was passed or an argument was outside its domain. in particular,kmust be a valid index ofstring, which in turn must be a mutable string. no shortcuts, bestie π€- R7RS β the assertions described above are errors. implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically. π yes they really said that. catastrophic. read it and weep.
β SEE ALSO β
open-string-output-port(3scm) β the glow-up alternative π
π STANDARDS π
R4RS, IEEE Scheme, R5RS, R6RS, R7RS β she's certified, she's legit, she's been vetted π¦β¨
π HISTORY π
the first Scheme report to include this procedure was R2RS. in R6RS this procedure was moved to its own library which is normally not imported. so like... she got her own apartment and nobody visits π still iconic though π
π AUTHORS π
this page is part of the scheme-manpages project π«Ά it includes materials from the RnRS documents. more information can be found at https://github.com/schemedoc/manpages/ β go show them some love fr fr π
okay that's the whole page bestie, you're officially educated β¨ this was the string-set!(3scm) page from the Scheme Programmer's Manual, dated 2022-05-14, brought to you by the scheme-manpages project β now go forth and mutate responsibly, or don't, whatever, mwah ππ
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2022 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms