OPEN-FILE-INPUT-PORT(3scm)
okay bestie, this is the open-file-input-port(3scm) page from the Scheme Programmer's Manual β and it's literally all about opening a file for reading. Group chat, gather round. π
π NAME π
open-file-input-port β open a file for reading. That's the whole plot, and it ate. π
π LIBRARY π
(import (rnrs)) ;R6RS
(import (rnrs io ports)) ;R6RS
β¨ SYNOPSIS β¨
(open-file-input-port filename)
(open-file-input-port filename file-options)
(open-file-input-port filename file-options buffer-mode)
(open-file-input-port filename file-options buffer-mode maybe-transcoder)
πΈ DESCRIPTION πΈ
Returns an input port for the named file. Slay. π
- The
file-optionsargument defaults to the value of(file-options). Heads up: the standard file options do nothing for input ports. - The
buffer-modeargument must be one of the symbols that name a buffer mode. It defaults toblock. Also, note that line buffering is unlikely to be effective on input ports.
π¦ Textual ports π¦
If maybe-transcoder is a transcoder, it becomes the transcoder associated with the returned port. The port will then be a textual port. Cute. β¨
π§ Binary ports π§
If maybe-transcoder is #f or absent, the port will be a binary port.
π Port positioning π
The port will support the port-position(3scm) and set-port-position!(3scm) operations if it is a binary port. Otherwise support is implementation-dependent, and possibly transcoder-dependent. iykyk. π«
π«Ά RETURN VALUES π«Ά
Returns a single value; a binary or textual input port. One value, no drama.
π EXAMPLES π
No cap, here's the example β it returns all records in /etc/passwd:
;; Return all records in /etc/passwd
(call-with-port
(open-file-input-port "/etc/passwd"
(file-options)
(buffer-mode block)
(native-transcoder))
(lambda (p)
(let lp ()
(let ((line (get-line p)))
(if (eof-object? line)
'()
(cons line (lp)))))))
π APPLICATION USAGE π
This is used in applications that open binary files, and ones that open textual files while needing control over the transcoder. Very demure, very mindful. π
π COMPATIBILITY π
This procedure is unique to R6RS. Other RnRS revisions have open-input-file(3scm), which is also in R6RS. History lesson, bestie. π
π¨ ERRORS π¨
This procedure can raise exceptions with the following condition types:
&assertion(R6RS) β The wrong number of arguments was passed or an argument was outside its domain. In particular,maybe-transcodermust be either a transcoder or#f.- 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. ππ
π SEE ALSO π
file-options(7scm)buffer-mode(7scm)open-input-file(3scm)open-file-output-port(3scm)
β STANDARDS β
R6RS. That's it, that's the standard. β¨
π₯ HISTORY π₯
First appeared in the reworked I/O system in R6RS. A glow-up moment, fr fr. π
π 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/.
π okay that's the whole page β source/version tag: open-file-input-port(3scm), date: 2022-05-10. Byeeee! ππ
π¦ 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