os

package
v0.43.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2024 License: ISC Imports: 11 Imported by: 1

README

The package os provides variadic function definitions for IO/OS builtins.

This package offers quite simple IO functionality and is written in portable Go (except for code related to the shell builtin). However, to run the tests, you currently need a functional /bin/sh and a goal executable in your $PATH.

Documentation

Overview

Package os provides variadic function definitions for IO/OS builtins.

The variadic functions defined in this package can each be picked and registered individually, or all at once using the convenience Import function.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Import added in v0.39.0

func Import(ctx *goal.Context, pfx string)

Import is a convenience function that registers in the given Context all the variadic functions exported by the package with default names and valence. It also assigns standard filehandles to globals. If the given prefix string is not empty, it is used as a common dot prefix for names

func NewFileReader added in v0.25.0

func NewFileReader(f *os.File) goal.V

NewFileReader returns a buffered reader handle for the given file.

func NewFileWriter added in v0.25.0

func NewFileWriter(f *os.File) goal.V

NewFileWriter returns a buffered writer handle for the given file.

func VFChdir added in v0.10.0

func VFChdir(ctx *goal.Context, args []goal.V) goal.V

VFChdir implements the chdir monad.

chdir s : change current directory to s, or return an error.

It returns a true value on success.

func VFClose added in v0.10.0

func VFClose(ctx *goal.Context, args []goal.V) goal.V

VFClose implements the close monad.

close h : flush any buffered data, then close handle.

It returns a true value on success, and an error otherwise.

func VFEnv added in v0.10.0

func VFEnv(ctx *goal.Context, args []goal.V) goal.V

VFEnv implements the env dyad.

env s : retrieve environment variable s, or return an error if unset. As a special case, "" returns a dictionary representing the whole environment.

x env s : sets the value of the environment variable x to s. It returns a true value of success, and an error otherwise. Also, the special form env[x;0] unsets a variable, and as a special case, env["";0] clears the whole environment.

func VFFlush added in v0.10.0

func VFFlush(ctx *goal.Context, args []goal.V) goal.V

VFFlush implements the flush monad.

flush h : flushes any buffered data for handle or any value type with a Flush method.

It returns a true value on success, and an error otherwise.

func VFImport added in v0.10.0

func VFImport(ctx *goal.Context, args []goal.V) goal.V

VFImport implements the import dyad.

import s : read/eval wrapper roughly equivalent to eval[read path;path;pfx] where 1) path~s or path~env["GOALLIB"]+s+".goal" 2) pfx is path's basename without extension.

x import s : same as import s but use prefix x for globals. If x is empty, no prefix is used.

It returns 0 and does nothing if a file has already been evaluated.

func VFMkdir added in v0.25.0

func VFMkdir(ctx *goal.Context, args []goal.V) goal.V

VFMkdir implements the mkdir monad.

mkdir s : create directory s or return an error.

It returns the number of directories created, or an error.

func VFOpen added in v0.10.0

func VFOpen(ctx *goal.Context, args []goal.V) goal.V

VFOpen implements the open dyad.

open s : opens path s for reading.

x open s : open path s with mode x in "r" "w" "a" (file read/write/append) or pipe from or to command s or S with "pr" "pw" (pipe read/write).

(synonymous modes: "<" ">" ">>" "-|" "|-")

It returns a filehandle value of type "h" on success, and an error otherwise.

func VFPrint added in v0.10.0

func VFPrint(ctx *goal.Context, args []goal.V) goal.V

VFPrint implements the print dyad.

print x : outputs x to standard output. It returns a true value on success. It uses implicit conversion to string for non-string inputs.

x print y : outputs y to x, where x is an io.Writer handle or a filename (goal.S).

func VFRead added in v0.10.0

func VFRead(ctx *goal.Context, args []goal.V) goal.V

VFRead implements the read dyad.

read h : reads from handle h until EOF or an error occurs.

read s : reads file into string or directory into dictionary with keys "dir""name".

s read h : reads from handle h until delimiter s or EOF, or an error occurs.

i read h : reads i bytes from handle h until EOF (returning possibly less than i bytes) or an error occurs.

It returns the read content as a string on success, and an error otherwise.

func VFRemove added in v0.25.0

func VFRemove(ctx *goal.Context, args []goal.V) goal.V

VFRemove implements the remove monad.

remove s : remove the named file or empty directory.

It returns the number of files removed, or an error.

func VFRename added in v0.25.0

func VFRename(ctx *goal.Context, args []goal.V) goal.V

VFRename implements the rename dyad.

rename[old;new] : rename path old to new.

It returns a true value on success, and an error otherwise.

func VFRun added in v0.10.0

func VFRun(ctx *goal.Context, args []goal.V) goal.V

VFRun implements the run dyad.

run s : run command s, with arguments if s is an array.

x run s : run command s, with input string x as standard input.

In the first form, standard input and error are inherited from the parent. In the second form, only standard error is inherited. Both commands return their own standard output, or an error.

func VFSay added in v0.10.0

func VFSay(ctx *goal.Context, args []goal.V) goal.V

VFSay implements the say dyad. It is the same as print, but appends a newline to the result.

func VFShell added in v0.10.0

func VFShell(ctx *goal.Context, args []goal.V) goal.V

VFShell implements the shell dyad. It works like the run dyad, but runs a single string command through /bin/sh instead.

func VFStat added in v0.25.0

func VFStat(ctx *goal.Context, args []goal.V) goal.V

VFStat implements the stat monad.

stat x : return dict "size""mode""mtime"!(i;i;i) for path or filehandle or any value type with Stat method with same signature as os.Stat.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL