The files library - pf-lang/pipefish GitHub Wiki

As file-handling is an essentially imperative, impure activity, Pipefish must do it through commands, not functions. Pipefish and its libraries use a standard form of syntax for IO, based on HTTP, in which the verbs post, put, get, and delete describe interactions with the external data.

These are applied to structs which say what we're posting to or getting from, e.g:

main :
    get fileExists from FileExists("foo.txt")
    fileExists :
        get text from File("foo.txt")
        post text
    else :
        error "can't open `foo.txt`"

In this example, FileExists and File are each constructors of structs, with each type of struct having one field, filepath. The get instruction then dispatches on the type of the struct.

This library will be extended as I find what is necessary and ergonomic.

Types

The library declares the following types.

  • File = struct(filepath string)
  • FileExists = struct(filepath string)
  • FileSearchMode = enum NONRECURSIVE, RECURSIVE
  • Filenames = struct(directory string, fileSearchMode FileSearchMode)
  • DirectoryNames = struct(directory string, fileSearchMode FileSearchMode)

Commands

It supplies the following commands:

get (names ref) from (filenames Filenames)

get (names ref) from (directoryNames DirectoryNames)

get (contents ref) from (file File)

get (x ref) from (file FileExists)

put (s string) into (file File)

delete (file File)