standard-input-port(3scm)
π 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 useflush-output-port(3scm)orclose-port(3scm)on these ports before exiting, or usecall-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
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2023 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms