OPEN-FILE-INPUT-PORT(3scm)

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

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-options argument defaults to the value of (file-options). Heads up: the standard file options do nothing for input ports.
  • The buffer-mode argument must be one of the symbols that name a buffer mode. It defaults to block. 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-transcoder must 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