put-string(3scm)
π 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
displaycan'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:
put-char(3scm)display(3scm)open-file-output-port(3scm)
β STANDARDS
R6RS, R7RS β yes both. she contains multitudes π
πΈ HISTORY
put-stringwas introduced in R6RS as part of the reworked I/O design. glow-up era β¨write-stringis 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
- 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