standard-input-port(3scm)

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

πŸ’… standard-input-port, standard-output-port, standard-error-port πŸ’…

okay bestie, you’re reading the standard-input-port(3scm) page from the Scheme Programmer's Manual, and it’s giving fresh-port main character energy. Lowkey essential, highkey iconic. Let’s get into it πŸ’–

πŸŽ€ NAME πŸŽ€

standard-input-port, standard-output-port, standard-error-port β€” fresh standard I/O ports, periodt.

πŸ“š LIBRARY πŸ“š

(import (rnrs))                     ;R6RS
(import (rnrs io ports))            ;R6RS

✨ SYNOPSIS ✨

(standard-input-port)
(standard-output-port)
(standard-error-port)

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so these return a fresh binary port connected to standard input, standard output, or standard error respectively β€” matching the procedure name, no cap. The first one returns an input port, and the latter two return output ports.

Whether port-position(3scm) and set-port-position!(3scm) work on the port is implementation-dependent. That’s a vibe check you have to do with your implementation, bestie.

πŸ’– RETURN VALUES πŸ’–

One single value comes back: a fresh port. That’s it, that’s the whole flex.

🌸 EXAMPLES 🌸

The following program converts its standard input from ISO-8859-1 to UTF-8 on its standard output.

(import (rnrs))

(call-with-port
    (transcoded-port (standard-input-port)
                     (make-transcoder (latin-1-codec)))
  (lambda (inp)
    (call-with-port
        (transcoded-port (standard-output-port)
                         (make-transcoder (utf-8-codec)))
      (lambda (outp)
        (let lp ()
          (let ((c (get-char inp)))
            (unless (eof-object? c)
              (put-char outp c)
              (lp))))))))

🧚 APPLICATION USAGE 🧚

This exists for applications that need binary I/O on standard input, standard output, and standard error. It can also be used to create transcoded ports when the default transcoder on current-input-port(3scm) etc is not what you want. Obsessed with a little port remix, honestly.

πŸ”₯ RATIONALE πŸ”₯

Basically, these three are how you get binary I/O on standard input, output, and error. Main character energy for binary stdio, fr fr.

🌈 COMPATIBILITY 🌈

Bestie, these procedures are unique to R6RS. There is nothing similar in R7RS, but some implementations will, as an extension, allow binary I/O on textual ports. Chibi-Scheme is an example of such an implementation. Iykyk.

πŸ’€ ERRORS πŸ’€

This procedure can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” the wrong number of arguments was passed. Not me getting the arg count wrong and catching an assertion πŸ’….

πŸ‘€ SEE ALSO πŸ‘€

current-input-port(3scm), make-transcoder(3scm)

⭐ STANDARDS ⭐

R6RS

πŸ•°οΈ HISTORY πŸ•°οΈ

These procedures are new to the reworked I/O in R6RS. Fresh out the R6RS I/O glow-up, periodt.

πŸ‘‘ 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/.

πŸ› BUGS πŸ›

bestie, please listen: programs should use flush-output-port(3scm) or close-port(3scm) on these ports before exiting, or use call-with-port(3scm). The ports can be buffered and not all implementations flush open ports at exit. That’s the danger zone β€” don’t just dip without flushing, okay? 😭

source/version: standard-input-port(3scm) β€” date: 2023-02-20 β€” made with πŸ’– and a final little bow πŸŽ€, periodt.

πŸ“¦ where this page comes from