updating documents for stdlib

This commit is contained in:
Daniel Kang 2019-01-29 20:46:30 -08:00
parent 306fe1b24c
commit 591d745ef7
5 changed files with 182 additions and 196 deletions

View file

@ -67,7 +67,7 @@ var mathModule = map[string]objects.Object{
"sqrt": FuncAFRF(math.Sqrt),
"tan": FuncAFRF(math.Tan),
"tanh": FuncAFRF(math.Tanh),
"runct": FuncAFRF(math.Trunc),
"trunc": FuncAFRF(math.Trunc),
"y0": FuncAFRF(math.Y0),
"y1": FuncAFRF(math.Y1),
"yn": FuncAIFRF(math.Yn),

View file

@ -1,28 +0,0 @@
# Module - "exec"
```golang
exec := import("exec")
```
## Module Functions
- `look_path(file string) => string/error`: port of `exec.LookPath` function
- `command(name string, args array(string)) => `Cmd/error`: port of `exec.Command` function
## Cmd Functions
```golang
cmd := exec.command("echo", ["foo", "bar"])
output := cmd.output()
```
- `combined_output() => bytes/error`: port of `exec.Cmd.CombinedOutput` function
- `output() => bytes/error`: port of `exec.Cmd.Output` function
- `combined_output() => bytes/error`: port of `exec.Cmd.CombinedOutput` function
- `run() => error`: port of `exec.Cmd.Run` function
- `start() => error`: port of `exec.Cmd.Start` function
- `wait() => error`: port of `exec.Cmd.Wait` function
- `set_path(path string)`: sets `Path` of `exec.Cmd`
- `set_dir(dir string)`: sets `Dir` of `exec.Cmd`
- `set_env(env array(string))`: sets `Env` of `exec.Cmd`
- `process() => Process`: returns Process (`Process` of `exec.Cmd`)

View file

@ -4,76 +4,72 @@
math := import("math")
```
## Variables
## Constants
- `e`: equivalent of Go's `math.E`
- `pi`: equivalent of Go's `math.Pi`
- `phi`: equivalent of Go's `math.Phi`
- `sqrt2`: equivalent of Go's `math.Sqrt2`
- `sqrtE`: equivalent of Go's `math.SqrtE`
- `sprtPi`: equivalent of Go's `math.SqrtPi`
- `sqrtPhi`: equivalent of Go's `math.SqrtPhi`
- `ln2`: equivalent of Go's `math.Ln2`
- `log2E`: equivalent of Go's `math.Log2E`
- `ln10`: equivalent of Go's `math.Ln10`
- `ln10E`: equivalent of Go's `math.Log10E`
- `e`
- `pi`
- `phi`
- `sqrt2`
- `sqrtE`
- `sprtPi`
- `sqrtPhi`
- `ln2`
- `log2E`
- `ln10`
- `ln10E`
## Functions
- `abs(float) => float`: port of Go's `math.Abs` function
- `acos(float) => float`: port of Go's `math.Acos` function
- `acosh(float) => float`: port of Go's `math.Acosh` function
- `asin(float) => float`: port of Go's `math.Asin` function
- `asinh(float) => float`: port of Go's `math.Asinh` function
- `atan(float) => float`: port of Go's `math.Atan` function
- `atan2(float, float) => float`: port of Go's `math.Atan2` function
- `atanh(float) => float`: port of Go's `math.Atanh` function
- `cbrt(float) => float`: port of Go's `math.Cbrt` function
- `ceil(float) => float`: port of Go's `math.Ceil` function
- `copysign(float, float) => float`: port of Go's `math.Copysign` function
- `cos(float) => float`: port of Go's `math.Cos` function
- `cosh(float) => float`: port of Go's `math.Cosh` function
- `dim(float, float) => float`: port of Go's `math.Dim` function
- `erf(float) => float`: port of Go's `math.Erf` function
- `erfc(float) => float`: port of Go's `math.Erfc` function
- `erfcinv(float) => float`: port of Go's `math.Erfcinv` function
- `erfinv(float) => float`: port of Go's `math.Erfinv` function
- `exp(float) => float`: port of Go's `math.Exp` function
- `exp2(float) => float`: port of Go's `math.Exp2` function
- `expm1(float) => float`: port of Go's `math.Expm1` function
- `floor(float) => float`: port of Go's `math.Floor` function
- `gamma(float) => float`: port of Go's `math.Gamma` function
- `hypot(float, float) => float`: port of Go's `math.Hypot` function
- `ilogb(float) => float`: port of Go's `math.Ilogb` function
- `inf(int) => float`: port of Go's `math.Inf` function
- `is_inf(float, int) => float`: port of Go's `math.IsInf` function
- `is_nan(float) => float`: port of Go's `math.IsNaN` function
- `j0(float) => float`: port of Go's `math.J0` function
- `j1(float) => float`: port of Go's `math.J1` function
- `jn(int, float) => float`: port of Go's `math.Jn` function
- `ldexp(float, int) => float`: port of Go's `math.Ldexp` function
- `log(float) => float`: port of Go's `math.Log` function
- `log10(float) => float`: port of Go's `math.Log10` function
- `log1p(float) => float`: port of Go's `math.Log1p` function
- `log2(float) => float`: port of Go's `math.Log2` function
- `logb(float) => float`: port of Go's `math.Logb` function
- `max(float, float) => float`: port of Go's `math.Max` function
- `min(float, float) => float`: port of Go's `math.Min` function
- `mod(float, float) => float`: port of Go's `math.Mod` function
- `nan() => float`: port of Go's `math.NaN` function
- `nextafter(float, float) => float`: port of Go's `math.Nextafter` function
- `pow(float, float) => float`: port of Go's `math.Pow` function
- `pow10(int) => float`: port of Go's `math.Pow10` function
- `remainder(float, float) => float`: port of Go's `math.Remainder` function
- `round(float) => float`: port of Go's `math.Round` function
- `round_to_even(float) => float`: port of Go's `math.RoundToEven` function
- `signbit(float) => float`: port of Go's `math.Signbit` function
- `sin(float) => float`: port of Go's `math.Sin` function
- `sinh(float) => float`: port of Go's `math.Sinh` function
- `sqrt(float) => float`: port of Go's `math.Sqrt` function
- `tan(float) => float`: port of Go's `math.Tan` function
- `tanh(float) => float`: port of Go's `math.Tanh` function
- `runct(float) => float`: port of Go's `math.Trunc` function
- `y0(float) => float`: port of Go's `math.Y0` function
- `y1(float) => float`: port of Go's `math.Y1` function
- `yn(int, float) => float`: port of Go's `math.Yn` function
- `abs(x float) => float`: returns the absolute value of x.
- `acos(x float) => float`: returns the arccosine, in radians, of x.
- `acosh(x float) => float`: returns the inverse hyperbolic cosine of x.
- `asin(x float) => float`: returns the arcsine, in radians, of x.
- `asinh(x float) => float`: returns the inverse hyperbolic sine of x.
- `atan(x float) => float`: returns the arctangent, in radians, of x.
- `atan2(y float, xfloat) => float`: returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.
- `atanh(x float) => float`: returns the inverse hyperbolic tangent of x.
- `cbrt(x float) => float`: returns the cube root of x.
- `ceil(x float) => float`: returns the least integer value greater than or equal to x.
- `copysign(x float, y float) => float`: returns a value with the magnitude of x and the sign of y.
- `cos(x float) => float`: returns the cosine of the radian argument x.
- `cosh(x float) => float`: returns the hyperbolic cosine of x.
- `dim(x float, y float) => float`: returns the maximum of x-y or 0.
- `erf(x float) => float`: returns the error function of x.
- `erfc(x float) => float`: returns the complementary error function of x.
- `exp(x float) => float`: returns e**x, the base-e exponential of x.
- `exp2(x float) => float`: returns 2**x, the base-2 exponential of x.
- `expm1(x float) => float`: returns e**x - 1, the base-e exponential of x minus 1. It is more accurate than Exp(x) - 1 when x is near zero.
- `floor(x float) => float`: returns the greatest integer value less than or equal to x.
- `gamma(x float) => float`: returns the Gamma function of x.
- `hypot(p float, q float) => float`: returns Sqrt(p * p + q * q), taking care to avoid unnecessary overflow and underflow.
- `ilogb(x float) => float`: returns the binary exponent of x as an integer.
- `inf(sign int) => float`: returns positive infinity if sign >= 0, negative infinity if sign < 0.
- `is_inf(f float, sign int) => float`: reports whether f is an infinity, according to sign. If sign > 0, IsInf reports whether f is positive infinity. If sign < 0, IsInf reports whether f is negative infinity. If sign == 0, IsInf reports whether f is either infinity.
- `is_nan(f float) => float`: reports whether f is an IEEE 754 ``not-a-number'' value.
- `j0(x float) => float`: returns the order-zero Bessel function of the first kind.
- `j1(x float) => float`: returns the order-one Bessel function of the first kind.
- `jn(n int, x float) => float`: returns the order-n Bessel function of the first kind.
- `ldexp(frac float, exp int) => float`: is the inverse of frexp. It returns frac × 2**exp.
- `log(x float) => float`: returns the natural logarithm of x.
- `log10(x float) => float`: returns the decimal logarithm of x.
- `log1p(x float) => float`: returns the natural logarithm of 1 plus its argument x. It is more accurate than Log(1 + x) when x is near zero.
- `log2(x float) => float`: returns the binary logarithm of x.
- `logb(x float) => float`: returns the binary exponent of x.
- `max(x float, y float) => float`: returns the larger of x or y.
- `min(x float, y float) => float`: returns the smaller of x or y.
- `mod(x float, y float) => float`: returns the floating-point remainder of x/y.
- `nan() => float`: returns an IEEE 754 ``not-a-number'' value.
- `nextafter(x float, y float) => float`: returns the next representable float64 value after x towards y.
- `pow(x float, y float) => float`: returns x**y, the base-x exponential of y.
- `pow10(n int) => float`: returns 10**n, the base-10 exponential of n.
- `remainder(x float, y float) => float`: returns the IEEE 754 floating-point remainder of x/y.
- `signbit(x float) => float`: returns true if x is negative or negative zero.
- `sin(x float) => float`: returns the sine of the radian argument x.
- `sinh(x float) => float`: returns the hyperbolic sine of x.
- `sqrt(x float) => float`: returns the square root of x.
- `tan(x float) => float`: returns the tangent of the radian argument x.
- `tanh(x float) => float`: returns the hyperbolic tangent of x.
- `trunc(x float) => float`: returns the integer value of x.
- `y0(x float) => float`: returns the order-zero Bessel function of the second kind.
- `y1(x float) => float`: returns the order-one Bessel function of the second kind.
- `yn(n int, x float) => float`: returns the order-n Bessel function of the second kind.

View file

@ -4,82 +4,84 @@
os := import("os")
```
## Module Variables
## Constants
- `o_rdonly`: equivalent of Go's `os.O_RDONLY`
- `o_wronly`: equivalent of Go's `os.O_WRONLY`
- `o_rdwr`: equivalent of Go's `os.O_RDWR`
- `o_append`: equivalent of Go's `os.O_APPEND`
- `o_create`: equivalent of Go's `os.O_CREATE`
- `o_excl`: equivalent of Go's `os.O_EXCL`
- `o_sync`: equivalent of Go's `os.O_SYNC`
- `o_trunc`: equivalent of Go's `os.O_TRUNC`
- `mode_dir`: equivalent of Go's `os.ModeDir`
- `mode_append`: equivalent of Go's `os.ModeAppend`
- `mode_exclusive`: equivalent of Go's `os.ModeExclusive`
- `mode_temporary`: equivalent of Go's `os.ModeTemporary`
- `mode_symlink`: equivalent of Go's `os.ModeSymlink`
- `mode_device`: equivalent of Go's `os.ModeDevice`
- `mode_named_pipe`: equivalent of Go's `os.ModeNamedPipe`
- `mode_socket`: equivalent of Go's `os.ModeSocket`
- `mode_setuid`: equivalent of Go's `os.ModeSetuid`
- `mode_setgui`: equivalent of Go's `os.ModeSetgid`
- `mode_char_device`: equivalent of Go's `os.ModeCharDevice`
- `mode_sticky`: equivalent of Go's `os.ModeSticky`
- `mode_irregular`: equivalent of Go's `os.ModeIrregular`
- `mode_type`: equivalent of Go's `os.ModeType`
- `mode_perm`: equivalent of Go's `os.ModePerm`
- `seek_set`: equivalent of Go's `os.SEEK_SET`
- `seek_cur`: equivalent of Go's `os.SEEK_CUR`
- `seek_end`: equivalent of Go's `os.SEEK_END`
- `path_separator`: equivalent of Go's `os.PathSeparator`
- `path_list_separator`: equivalent of Go's `os.PathListSeparator`
- `dev_null`: equivalent of Go's `os.DevNull`
- `o_rdonly`
- `o_wronly`
- `o_rdwr`
- `o_append`
- `o_create`
- `o_excl`
- `o_sync`
- `o_trunc`
- `mode_dir`
- `mode_append`
- `mode_exclusive`
- `mode_temporary`
- `mode_symlink`
- `mode_device`
- `mode_named_pipe`
- `mode_socket`
- `mode_setuid`
- `mode_setgui`
- `mode_char_device`
- `mode_sticky`
- `mode_irregular`
- `mode_type`
- `mode_perm`
- `seek_set`
- `seek_cur`
- `seek_end`
- `path_separator`
- `path_list_separator`
- `dev_null`
## Module Functions
- `args() => array(string)`: returns `os.Args`
- `chdir(dir string) => error`: port of `os.Chdir` function
- `chmod(name string, mode int) => error `: port of Go's `os.Chmod` function
- `chown(name string, uid int, gid int) => error `: port of Go's `os.Chown` function
- `clearenv() `: port of Go's `os.Clearenv` function
- `environ() => array(string) `: port of Go's `os.Environ` function
- `executable() => string/error`: port of Go's `os.Executable()` function
- `exit(code int) `: port of Go's `os.Exit` function
- `expand_env(s string) => string `: port of Go's `os.ExpandEnv` function
- `getegid() => int `: port of Go's `os.Getegid` function
- `getenv(s string) => string `: port of Go's `os.Getenv` function
- `geteuid() => int `: port of Go's `os.Geteuid` function
- `getgid() => int `: port of Go's `os.Getgid` function
- `getgroups() => array(string)/error `: port of Go's `os.Getgroups` function
- `getpagesize() => int `: port of Go's `os.Getpagesize` function
- `getpid() => int `: port of Go's `os.Getpid` function
- `getppid() => int `: port of Go's `os.Getppid` function
- `getuid() => int `: port of Go's `os.Getuid` function
- `getwd() => string/error `: port of Go's `os.Getwd` function
- `hostname() => string/error `: port of Go's `os.Hostname` function
- `lchown(name string, uid int, gid int) => error `: port of Go's `os.Lchown` function
- `link(oldname string, newname string) => error `: port of Go's `os.Link` function
- `lookup_env(key string) => string/false`: port of Go's `os,LookupEnv` function
- `mkdir(name string, perm int) => error `: port of Go's `os.Mkdir` function
- `mkdir_all(name string, perm int) => error `: port of Go's `os.MkdirAll` function
- `readlink(name string) => string/error `: port of Go's `os.Readlink` function
- `remove(name string) => error `: port of Go's `os.Remove` function
- `remove_all(name string) => error `: port of Go's `os.RemoveAll` function
- `rename(oldpath string, newpath string) => error `: port of Go's `os.Rename` function
- `setenv(key string, value string) => error `: port of Go's `os.Setenv` function
- `symlink(oldname string newname string) => error `: port of Go's `os.Symlink` function
- `temp_dir() => string `: port of Go's `os.TempDir` function
- `truncate(name string, size int) => error `: port of Go's `os.Truncate` function
- `unsetenv(key string) => error `: port of Go's `os.Unsetenv` function
- `user_cache_dir() => string/error `: port of Go's `os.UserCacheDir` function
- `create(name string) => File/error`: port of Go's `os.Create` function
- `open(name string) => File/error`: port of Go's `os.Open` function
- `open_file(name string, flag int, perm int) => File/error`: port of Go's `os.OpenFile` function
- `find_process(pid int) => Process/error`: port of Go's `os.FindProcess` function
- `start_process(name string, argv array(string), dir string, env array(string)) => Process/error`: port of Go's `os.StartProcess` function
## Functions
## File Functions
- `args() => [string]`: returns command-line arguments, starting with the program name.
- `chdir(dir string) => error`: changes the current working directory to the named directory.
- `chmod(name string, mode int) => error `: changes the mode of the named file to mode.
- `chown(name string, uid int, gid int) => error `: changes the numeric uid and gid of the named file.
- `clearenv()`: deletes all environment variables.
- `environ() => [string] `: returns a copy of strings representing the environment.
- `exit(code int) `: causes the current program to exit with the given status code.
- `expand_env(s string) => string `: replaces ${var} or $var in the string according to the values of the current environment variables.
- `getegid() => int `: returns the numeric effective group id of the caller.
- `getenv(key string) => string `: retrieves the value of the environment variable named by the key.
- `geteuid() => int `: returns the numeric effective user id of the caller.
- `getgid() => int `: returns the numeric group id of the caller.
- `getgroups() => [int]/error `: returns a list of the numeric ids of groups that the caller belongs to.
- `getpagesize() => int `: returns the underlying system's memory page size.
- `getpid() => int `: returns the process id of the caller.
- `getppid() => int `: returns the process id of the caller's parent.
- `getuid() => int `: returns the numeric user id of the caller.
- `getwd() => string/error `: returns a rooted path name corresponding to the current directory.
- `hostname() => string/error `: returns the host name reported by the kernel.
- `lchown(name string, uid int, gid int) => error `: changes the numeric uid and gid of the named file.
- `link(oldname string, newname string) => error `: creates newname as a hard link to the oldname file.
- `lookup_env(key string) => string/false`: retrieves the value of the environment variable named by the key.
- `mkdir(name string, perm int) => error `: creates a new directory with the specified name and permission bits (before umask).
- `mkdir_all(name string, perm int) => error `: creates a directory named path, along with any necessary parents, and returns nil, or else returns an error.
- `readlink(name string) => string/error `: returns the destination of the named symbolic link.
- `remove(name string) => error `: removes the named file or (empty) directory.
- `remove_all(name string) => error `: removes path and any children it contains.
- `rename(oldpath string, newpath string) => error `: renames (moves) oldpath to newpath.
- `setenv(key string, value string) => error `: sets the value of the environment variable named by the key.
- `symlink(oldname string newname string) => error `: creates newname as a symbolic link to oldname.
- `temp_dir() => string `: returns the default directory to use for temporary files.
- `truncate(name string, size int) => error `: changes the size of the named file.
- `unsetenv(key string) => error `: unsets a single environment variable.
- `create(name string) => File/error`: creates the named file with mode 0666 (before umask), truncating it if it already exists.
- `open(name string) => File/error`: opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.
- `open_file(name string, flag int, perm int) => File/error`: is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc.) and perm (before umask), if applicable.
- `find_process(pid int) => Process/error`: looks for a running process by its pid.
- `start_process(name string, argv [string], dir string, env [string]) => Process/error`: starts a new process with the program, arguments and attributes specified by name, argv and attr. The argv slice will become os.Args in the new process, so it normally starts with the program name.
- `exec_look_path(file string) => string/error`: searches for an executable named file in the directories named by the PATH environment variable.
- `exec(name string, args...) => Command/error`: returns the Command to execute the named program with the given arguments.
## File
```golang
file := os.create("myfile")
@ -87,31 +89,31 @@ file.write_string("some data")
file.close()
```
- `chdir() => true/error`: port of `os.File.Chdir` function
- `chown(uid int, gid int) => true/error`: port of `os.File.Chown` function
- `close() => error`: port of `os.File.Close` function
- `name() => string`: port of `os.File.Name` function
- `readdirnames() => array(string)/error`: port of `os.File.Readdirnames` function
- `sync() => error`: port of `os.File.Sync` function
- `write(bytes) => int/error`: port of `os.File.Write` function
- `write_string(string) => int/error`: port of `os.File.WriteString` function
- `read(bytes) => int/error`: port of `os.File.Read` function
- `chmod(mode int) => error`: port of `os.File.Chmod` function
- `seek(offset int, whence int) => int/error`: port of `os.File.Seek` function
- `chdir() => true/error`: changes the current working directory to the file,
- `chown(uid int, gid int) => true/error`: changes the numeric uid and gid of the named file.
- `close() => error`: closes the File, rendering it unusable for I/O.
- `name() => string`: returns the name of the file as presented to Open.
- `readdirnames(n int) => [string]/error`: reads and returns a slice of names from the directory.
- `sync() => error`: commits the current contents of the file to stable storage.
- `write(bytes) => int/error`: writes len(b) bytes to the File.
- `write_string(string) => int/error`: is like 'write', but writes the contents of string s rather than a slice of bytes.
- `read(bytes) => int/error`: reads up to len(b) bytes from the File.
- `chmod(mode int) => error`: changes the mode of the file to mode.
- `seek(offset int, whence int) => int/error`: sets the offset for the next Read or Write on file to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end.
## Process Functions
## Process
```golang
proc := start_process("app", ["arg1", "arg2"], "dir", [])
proc.wait()
```
- `kill() => error`: port of `os.Process.Kill` function
- `release() => error`: port of `os.Process.Release` function
- `signal(signal int) => error`: port of `os.Process.Signal` function
- `wait() => ProcessState/error`: port of `os.Process.Wait` function
- `kill() => error`: causes the Process to exit immediately.
- `release() => error`: releases any resources associated with the process, rendering it unusable in the future.
- `signal(signal int) => error`: sends a signal to the Process.
- `wait() => ProcessState/error`: waits for the Process to exit, and then returns a ProcessState describing its status and an error, if any.
## ProcessState Functions
## ProcessState
```golang
proc := start_process("app", ["arg1", "arg2"], "dir", [])
@ -119,7 +121,24 @@ stat := proc.wait()
pid := stat.pid()
```
- `exited() => bool`: port of `os.ProcessState.Exited` function
- `pid() => int`: port of `os.ProcessState.Pid` function
- `string() => string`: port of `os.ProcessState.String` function
- `success() => bool`: port of `os.ProcessState.Success` function
- `exited() => bool`: reports whether the program has exited.
- `pid() => int`: returns the process id of the exited process.
- `string() => string`: returns a string representation of the process.
- `success() => bool`: reports whether the program exited successfully, such as with exit status 0 on Unix.
```golang
cmd := exec.command("echo", ["foo", "bar"])
output := cmd.output()
```
## Command
- `combined_output() => bytes/error`: runs the command and returns its combined standard output and standard error.
- `output() => bytes/error`: runs the command and returns its standard output.
- `run() => error`: starts the specified command and waits for it to complete.
- `start() => error`: starts the specified command but does not wait for it to complete.
- `wait() => error`: waits for the command to exit and waits for any copying to stdin or copying from stdout or stderr to complete.
- `set_path(path string)`: sets the path of the command to run.
- `set_dir(dir string)`: sets the working directory of the process.
- `set_env(env [string])`: sets the environment of the process.
- `process() => Process`: returns the underlying process, once started.

View file

@ -1,7 +1,6 @@
# Standard Library
_Warning: standard library implementations/interfaces are **experimental** and subject to change in the future release._
- [math](https://github.com/d5/tengo/blob/master/docs/stdlib-math.md)
- [os](https://github.com/d5/tengo/blob/master/docs/stdlib-os.md)
- [exec](https://github.com/d5/tengo/blob/master/docs/stdlib-exec.md)
- [os](https://github.com/d5/tengo/blob/master/docs/stdlib-os.md): platform-independent interface to operating system functionality.
- [text](https://github.com/d5/tengo/blob/master/docs/stdlib-text.md): regular expressions, string conversion, and manipulation
- [math](https://github.com/d5/tengo/blob/master/docs/stdlib-math.md): mathematical constants and functions
- [times](https://github.com/d5/tengo/blob/master/docs/stdlib-times.md): time-related functions