put-string(3scm)

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

πŸ’… put-string, write-string β€” bestie edition

okay so this is from the Scheme Programmer's Manual (that's the 3scm part, iykyk) and it's literally just about yeeting a string into a textual output port. sit down, we're doing this ✨

πŸŽ€ NAME

put-string, write-string β€” write a string to a textual output port. that's it. that's the whole vibe.

πŸ“š LIBRARY

which import you need depends on your era, bestie:

(import (rnrs))                     ;R6RS
(import (rnrs io ports))            ;R6RS
(import (scheme base))              ;R7RS

🌸 SYNOPSIS

okay so there's two different girls here and you can't mix them up 🫢

R6RS only:

(put-string textual-output-port string)
(put-string textual-output-port string start)
(put-string textual-output-port string start count)

R7RS only:

(write-string string)
(write-string string textual-output-port)
(write-string string textual-output-port start)
(write-string string textual-output-port start end)

notice how R7RS puts the string first and the port second? yeah. iconic but confusing. stay awake πŸ’€

✨ DESCRIPTION

So basically: it writes the characters of string, starting at index start, to textual-output-port. cute, simple, done.

  • R6RS β€” exactly count characters get written, and count defaults to (string-length string) βˆ’ start. math girl behavior.
  • R7RS β€” the characters from start to end get written, with end defaulting to (string-length string).

and the start argument defaults to 0 in both, no cap 🧚

πŸ”₯ RETURN VALUES

  • R6RS β€” returns unspecified values. plural. multiple. none of your business.
  • R7RS β€” returns an unspecified value. singular. still none of your business.

πŸ“ EXAMPLES

here's the moment you've been waiting for:

(write-string "Hello, world!\n")

slay. go off. put it in a file, put it on stdout, live your truth πŸ’–

πŸ‘‘ APPLICATION USAGE

so why use this instead of a generic procedure like display (scheme)? two reasons, and they're both good:

  • it's slightly faster ⚑
  • it makes it possible to write only part of the string, which display can't do for you

lowkey the second one is the real reason. partial writes are the moment.

🌈 RATIONALE

the R7RS variant specifies end instead of count to be consistent with other procedures. so R6RS is out here counting and R7RS is out here indexing, and honestly? both valid. consistency won πŸ†

πŸ’€ ERRORS

this procedure can raise exceptions with the following condition types, so like… watch out:

  • &assertion (R6RS) β€” the wrong number of arguments was passed, or an argument was outside its domain. In particular, start and count must be non-negative exact integer objects, and string must have a length of at least start + count.
  • 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.
okay the "fail catastrophically" is not me being dramatic, that's a direct quote from the spec 😭 so like. please. pass valid arguments. for me. πŸ₯Ί

πŸ¦‹ SEE ALSO

go read these next, bestie, they're all in the same friend group:

⭐ STANDARDS

R6RS, R7RS β€” yes both. she contains multitudes πŸ’œ

🌸 HISTORY

  • put-string was introduced in R6RS as part of the reworked I/O design. glow-up era ✨
  • write-string is new in R7RS. fresh out the box 🎁

🫢 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 say hi to them, they did the work πŸ’–


okay and that's the whole page!! sign-off time: this was put-string(3scm), dated 2022-05-23, and that date is genuinely the last interesting fact I have for you. mwah πŸ’‹ go write some strings, bestie πŸŒˆπŸŽ€

πŸ“¦ where this page comes from