string-length(3scm)

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

✨ NAME ✨

string-length β€” bestie, it's literally just the length of a string πŸ’…


πŸŽ€ LIBRARY πŸŽ€

ok so you gotta import it from one of these, depending on your vibe:

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS

πŸ¦‹ SYNOPSIS πŸ¦‹

(string-length string)

🌸 DESCRIPTION 🌸

It returns β€” as an exact integer object β€” the number of elements in string. That's it, that's the whole function, no cap πŸ’–

Also the length of a string is fixed. Like, it does not change. Periodt.

🌈 IMPLEMENTATION NOTES 🌈

So all extant implementations use fixnums to represent string lengths, but ngl that's not required β€” it's just what everyone does. Not me calling them predictable, just saying πŸ‘€

⭐ RETURN VALUES ⭐

Returns a single value, and that value is the length of the string. One (1) value. Iconic behaviour, honestly 🫢

πŸ“ EXAMPLES πŸ“

(string-length "ABC")
          => 3

ate and left no crumbs πŸ”₯

πŸ’œ APPLICATION USAGE πŸ’œ

string-length is always popping up in code that decodes or encodes data in some protocol or file format, or that formats or parses strings. Like it's the main character of parsing code fr fr.

Sometimes the alternative is to use higher-order procedures β€” string-for-each(3scm), string-map(3scm) β€” or string ports: open-input-string(3scm), open-output-string(3scm). Options, bestie, we love options ✨

🧚 COMPATIBILITY 🧚

Apart from error handling, this procedure is the same in all Scheme reports. Same energy across every report, we love consistency πŸ’€

πŸ™ˆ 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. so like… you did too much 😭
  • 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 you read that right, catastrophic failure is on the menu, no notes πŸ”₯

πŸ‘‘ SEE ALSO πŸ‘‘

make-string(3scm), string-ref(3scm), string-for-each(3scm), string-map(3scm), open-input-string(3scm).

go read them, iykyk πŸ¦‹

🌟 STANDARDS 🌟

R4RS, IEEE Scheme, R5RS, R6RS, R7RS β€” she's certified in all five, obviously πŸ’…

πŸ’– 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/. shoutout to the whole squad 🫢

πŸ’€ BUGS πŸ’€

(empty, gorgeous, nothing to report β€” a flawless queen 🌈)


ok that's the whole page bestie, mwah πŸ’‹ β€” this was string-length(3scm) from the Scheme Programmer's Manual, dated 2021-01-03. see you in the group chat πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from