{"size": 1176, "ext": "scrbl", "max_stars_repo_path": "pkgs/racket-doc/scribblings/guide/ports.scrbl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": "2018-07-29T04:13:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T16:11:17.000Z", "max_issues_repo_path": "pkgs/racket-doc/scribblings/guide/ports.scrbl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2017-08-25T20:26:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:48:40.000Z", "max_forks_repo_path": "pkgs/racket-doc/scribblings/guide/ports.scrbl", "max_forks_repo_name": "lkh01/racket", "max_forks_repo_forks_event_min_datetime": "2016-04-25T11:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-09T14:52:48.000Z"}
{"max_stars_count": 10, "max_issues_count": 15, "max_forks_count": 3, "avg_line_length": 39.2, "max_line_length": 70, "alphanum_fraction": 0.7772108844}
#lang scribble/doc
@(require scribble/manual scribble/eval "guide-utils.rkt")

@title[#:tag "ports"]{Input and Output Ports}

A @deftech{port} encapsulates an I/O stream, normally for just one
direction. An @deftech{input port} reads from a stream, and an
@deftech{output port} writes to a string.

For many procedures that accept a port argument, the argument is
optional, and it defaults to either the @defterm{current input port}
or @defterm{current output port}. For @exec{mzscheme}, the current
ports are initialized to the process's stdin and stdout. The
@racket[current-input-port] and @racket[current-output-port]
procedures, when called with no arguments, return the current output
and input port, respectively.

@examples[
(display "hello world\n")
(display "hello world\n" (current-output-port))
]

Ports are created by various procedures that specific to the different
kinds of streams. For example, @racket[open-input-file] creates an
input port for reading from a file. Procedures like
@racket[with-input-from-file] both create a port and install it as the
current port while calling a given body procedure.

See @secref["io"] for information about using ports.
