put-char(3scm)
π put-char(3scm) β bestie's guide to yeeting a character into a port π
okay so this is a page from the Scheme Programmer's Manual and it's all about put-char and write-char, two little icons whose whole job is writing one single character to a port. tiny job, huge slay. let's get into it β¨
π¦ NAME
put-char, write-char β write a character to a port π
π LIBRARY
like, which library do you import? depends on your flavor, bestie:
(import (rnrs)) ;R6RS
(import (rnrs io ports)) ;R6RS, put-char
(import (rnrs io simple)) ;R6RS, write-char
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
β¨ SYNOPSIS
here's the whole vibe check, signature-wise:
(put-char textual-output-port char) ;R6RS
(write-char char)
(write-char char textual-output-port)
πΈ DESCRIPTION
It writes the character char to the textual-output-port. that's it. that's the whole procedure. lowkey iconic for how unbothered it is π«Ά
and if you're like "bestie I don't have a textual-output-port on me rn" β no worries, if textual-output-port is omitted it defaults to whatever value current-output-port(3scm) hands back. so you can just vibe and pass the char. π
π RETURN VALUES
Returns unspecified values. not gonna give you a whole value back, it's not that kind of procedure. π
π₯ EXAMPLES
okay this one's cute β a little sign-writer:
(define (write-with-sign n)
(write-char (if (negative? n) #\- #\+))
(write (abs n)))
and then:
(write-with-sign 10)
==> "+10"
(write-with-sign -12)
==> "-12"
see how the #\- vs #\+ picks the sign and then abs handles the digits? ate. no cap. π
π RATIONALE
so the tea is: put-char is the one that matches up with the reworked I/O system in R6RS. and write-char? that one got kept around for the simplified I/O system. both valid, different eras. π
π§ COMPATIBILITY
write-char is literally everywhere β it exists in all RnRS reports since R2RS. the longevity. the stamina. we stan a survivor. π
π ERRORS
this procedure can raise exceptions with the following condition types:
&assertion(R6RS) β you passed the wrong number of arguments, or an argument was outside its domain. (translation: wrong arg count or out-of-bounds arg, and it will tell you π)- 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, "fail catastrophically" is the actual wording and yes it's as dramatic as it sounds β like, genuinely, that's the documented behaviour, don't @ me. π₯
π SEE ALSO
display(3scm)fputc(3)
go read those too, iykyk π«Ά
β STANDARDS
R4RS, IEEE Scheme, R5RS, R6RS, R7RS β a whole little collection, periodt. π
πΈ HISTORY
write-char first showed up in R2RS. it has no direct predecessor in MacLisp, but it does exist in Common Lisp β so like, it's got cousins. π and put-char? first appeared in R6RS. late to the party but made an entrance. β¨
π 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/. shoutout to the maintainers, absolute legends π«Ά
π BUGS
IEEE Scheme accidentally omitted write-char.
that's it. that's the bug. an accidental omission. not me feeling a little bad for write-char π justice for the omitted icon!!
and that's the whole page, bestie π this cutie dropped as part of the scheme-manpages project (source/version vibes above in AUTHORS π) and the page itself is dated 2022-03-29 β so yeah, it's been out here being useful since then. mwah π go write some characters. π¦
π¦ 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