string-fill!(3scm)

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

πŸ’… string-fill!(3scm) β€” the Scheme Programmer's Manual, but make it cute

okay so bestie, welcome to string-fill!(3scm) β€” the little mutator that goes brrr on your strings ✨


🌸 NAME 🌸

string-fill! β€” fill a string with a character. that's it. that's the whole vibe πŸŽ€


πŸ“š LIBRARY πŸ“š

import it like this, depending on which flavour of Scheme you're living in:

(import (rnrs mutable-strings))     ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS

✨ SYNOPSIS ✨

(string-fill! string char)
(string-fill! string char start)      ;R7RS
(string-fill! string char start end)  ;R7RS

πŸ’– DESCRIPTION πŸ’–

So what it does: it stores char in every single element of string. every one. no survivors. it's giving total takeover πŸ‘‘

R7RS β€” okay so here's the glow-up: it only modifies string between start (inclusive, she's invited) and end (exclusive, she's NOT). and if you omit them? start defaults to 0 and end defaults to the length of string. defaults serving, honestly 🫢


πŸ¦‹ RETURN VALUES πŸ¦‹

  • R6RS β€” returns unspecified values. plural. don't ask what they are, nobody knows πŸ’€
  • R7RS β€” returns an unspecified value. singular. still a mystery.

πŸ“ EXAMPLES πŸ“

;; R7RS example
(let ((s (make-string 4 #\x)))
  (string-fill! s #\y 2)
  s)  =>  "xxyy"

see how the first two stayed x and only the last two got the y treatment? that's the start argument doing her thing. icon behaviour ✨


🌈 APPLICATION USAGE 🌈

This procedure is for filling strings that already exist β€” like, they've been created, they're living their life, and now you're filling them. lowkey it has marginal utility ngl 😭 because the second argument to make-string(3scm) fills the whole entire string right at creation time. so like... why not just do that? but hey, string-fill! is still here and she's still iconic πŸ’…


πŸŽ€ COMPATIBILITY πŸŽ€

The start and end arguments? Those are unique to R7RS. everyone else is not invited to that party πŸ™ˆ


πŸ’œ ERRORS πŸ’œ

This procedure can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” the wrong number of arguments was passed, or an argument was outside its domain. basically you did it wrong and it noticed 😭

R7RS β€” the assertions described above are errors. and here's the messy part: implementations may signal an error, or extend the procedure's domain of definition to include such arguments, or fail catastrophically. yes, catastrophically. the drama is real πŸ’€πŸ”₯


πŸ”₯ SEE ALSO πŸ”₯

  • make-string(3scm)
  • string-set!(3scm)

πŸ‘‘ STANDARDS πŸ‘‘

R4RS, R5RS, R6RS, R7RS β€” she's been standard-issue for a minute πŸ’…


🌸 HISTORY 🌸

The first Scheme report to carry this procedure was R2RS, and R2RS also had substring-fill! that filled a substring β€” but plot twist, it used a different argument order:

(substring-fill! string start end char)

anyway she's missing from IEEE Scheme. gone but not forgotten πŸ•―οΈ


🧚 AUTHORS 🧚

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. more info lives at https://github.com/schemedoc/manpages/.


fr fr bestie, that's the whole page. go fill some strings, and remember: start is inclusive, end is exclusive, and that's not a vibe, that's just the spec πŸ’–

signed off with love, 2022-05-14 edition of string-fill!(3scm) β€” Scheme Programmer's Manual 🫢

πŸ“¦ where this page comes from