string-copy(3scm)
π string-copy β copy a string π
okay so real talk, this page lives in the Scheme Programmer's Manual (that's the 3scm energy, iykyk) and it's about the single most useful little string move ever. let's get into it bestie π
β¨ NAME β¨
string-copy β copy a string. that's it. that's the whole vibe. literally just copying a string and slaying while doing it π
π¦ LIBRARY π¦
here's where you import it from, depending on your whole scheme situation:
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
pick your era, bestie, they all got you πΈ
β SYNOPSIS β
(string-copy string)
(string-copy string start) ;R7RS
(string-copy string start end) ;R7RS
so you can call it with just a string, or, in R7RS, with start and optionally end. the glow-up is real π
π DESCRIPTION π
it returns a newly allocated copy of the part of the given string between start and end. brand new object, fresh out the box, not sharing a vibe with the original. π«Ά
π§ IMPLEMENTATION NOTES π§
heads up: some implementations have a single empty string object which is returned if start = end, see make-string(3scm). so like... don't be weird about empty copies, they might all be the same little guy π
π RETURN VALUES π
returns a single value which is a string. one value. a string. no cap. β¨
π EXAMPLES π
the classic:
(string-copy "foo")
=> "foo"
and the R7RS slice moment:
;; R7RS
(string-copy "Hello" 1)
=> "ello"
ate. no crumbs. π₯
π APPLICATION USAGE π
okay so why does this even exist? this procedure makes sense in the presence of mutating string procedures like string-set!(3scm). it's commonly used to create copies of strings where there is an original copy of a string that should not be mutated by the receiver of the copy.
like β you're handing someone a string and you do NOT want them messing with your original. so you hand them a copy. boundaries, bestie. we love them π
π COMPATIBILITY π
this procedure is missing in IEEE Scheme. missing! absent! not invited to the function 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.- 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.
ngl that "fail catastrophically" line is highkey sending me π like okay drama queen, pop off
π SEE ALSO π
substring(3scm)string-copy!(3scm)
go read those next, they're the friends of this function fr fr π«Ά
πΈ STANDARDS πΈ
R4RS, R5RS, R6RS, R7RS. all four. certified. periodt π
β HISTORY β
the string-copy procedure first appeared in R2RS. a true original. main character energy from day one π
π 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/.
and that's the whole page bestie π this cutie was dated 2022-04-05 and it's brought to you by the scheme-manpages gang β go forth and copy those strings, but like, responsibly π
β¨
π¦ 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