string-set!(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

πŸŽ€ 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, k must be a valid index of string, 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