put-char(3scm)

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

πŸ’… 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

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