Started working on more package docs
This commit is contained in:
parent
f51c3ce891
commit
84702267df
9 changed files with 91 additions and 12 deletions
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
---
|
||||
|
||||
# Core Functions
|
||||
# Core Builtins
|
||||
|
||||
### call
|
||||
|
||||
|
|
@ -33,15 +33,16 @@ If COL is a hash, BLOCK receives both the key and value of each element.
|
|||
|
||||
BLOCK can call `break` and `continue` which will exit out of the loop, or jump to the start of the next iteration
|
||||
respectively.
|
||||
|
||||
The return value of `foreach` will be the result of the last iteration, unless `break` is called with a value.
|
||||
|
||||
This is implemented as a macro but can be used in a pipeline.
|
||||
|
||||
```
|
||||
foreach [1 2 3] { |e|
|
||||
echo "Element = $e"
|
||||
}
|
||||
|
||||
foreach [a:"one" b:"two"] { |k v|
|
||||
[a:"one" b:"two"] | foreach { |k v|
|
||||
echo "Key $k = $v"
|
||||
}
|
||||
```
|
||||
29
_docs/mod/csv.md
Normal file
29
_docs/mod/csv.md
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# CSV Module
|
||||
|
||||
Functions for operating over CSV data.
|
||||
|
||||
### each-record
|
||||
|
||||
```
|
||||
csv:each-record FILE BLOCK
|
||||
```
|
||||
|
||||
Opens the CSV file at FILE and calls BLOCK on each record. It is expected that this
|
||||
CSV file has a header which appears as the first row. This command will read and
|
||||
index the header, then start calling BLOCK from the row directly below the header.
|
||||
|
||||
BLOCK is called with the arguments _|row header|_ where:
|
||||
|
||||
- _row_ contains the fields of the current row as a list.
|
||||
- _header_ contains a hash mapping a header name to a field index.
|
||||
|
||||
The return value will be nil.
|
||||
|
||||
```
|
||||
csv:each-record "winds.csv" { |row hdr|
|
||||
set name $row.($hdr.name)
|
||||
set bearing $row.($hdr.bearing)
|
||||
|
||||
echo "Wind $name has bearing $bearing"
|
||||
}
|
||||
```
|
||||
11
_docs/mod/fs.md
Normal file
11
_docs/mod/fs.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# FS Module
|
||||
|
||||
Functions for accessing the file system.
|
||||
|
||||
### lines
|
||||
|
||||
```
|
||||
fs:lines FILE
|
||||
```
|
||||
|
||||
Returns a list containing the scanned lines of FILE.
|
||||
8
_docs/mod/index.md
Normal file
8
_docs/mod/index.md
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Modules
|
||||
|
||||
Modules of the standard library:
|
||||
|
||||
- [core](/mod/core): Core builtins
|
||||
- [csv](/mod/csv): Functions for operating over CSV data.
|
||||
- [fs](/mod/fs): File system functions
|
||||
- [os](/mod/os): Operating system functions
|
||||
17
_docs/mod/os.md
Normal file
17
_docs/mod/os.md
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# OS Module
|
||||
|
||||
Functions for accessing the operating system.
|
||||
|
||||
### env
|
||||
|
||||
```
|
||||
os:env NAME [DEFAULT]
|
||||
```
|
||||
|
||||
Returns the value of the environment variable NAME. If no environment with NAME
|
||||
is defined, then DEFAULT will be returned, if specified. Otherwise, nil will be
|
||||
returned.
|
||||
|
||||
```
|
||||
echo "User's home directory is: " (os:env "HOME")
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue