Skip to content
Snippets Groups Projects
Commit 0fe2d4ea authored by Michael Aaron Murphy's avatar Michael Aaron Murphy
Browse files

:book: Update the Ion API manual

parent 9e963106
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,6 @@
- [Introduction](introduction.md)
- [Feature Overview](features.md)
- [Miscellaneous](misc/index.md)
- [Implicit `cd`](misc/01-implicitcd.md)
......
......@@ -15,13 +15,43 @@ for element in @array
end
```
## Splitting Arguments
When working with strings that you would like to splice into multiple elements for iteration, see
the splicing method, `@split`:
```sh
let value = "one two three four"
for element in @split(value)
echo $element
end
```
By default, this will split a string by whitespace. Custom patterns may also be provided:
```sh
let value = "one,two,three,four"
for element in @split(value ',')
echo $element
end
```
A convenience method is also provided for `@split(value '\n')`: `@lines`
```sh
let file = $(cat file)
for line in @lines(file)
echo = $line =
end
```
## Breaking From Loops
Sometimes you may need to exit from the loop before the looping is finished. This is achievable
using the `break` keyword.
```sh
for element in {1...10}
for element in {1..=10}
echo $element
if test $element -eq 5
break
......@@ -42,7 +72,7 @@ In other times, if you need to abort further execution of the current loop and s
loop, the `continue` keyword serves that purpose.
```sh
for elem in {1...10}
for elem in {1..=10}
if test $((elem % 2)) -eq 1
continue
end
......
......@@ -24,7 +24,6 @@ $ echo $string:$string
**NOTE:**
- Accepted characters are **unicode** alphanumeric characters and **_**.
- If not double quoted, newlines will be replaced with spaces.
## Array Variables
......
......@@ -13,4 +13,3 @@ let array = @(cmd args...)
**NOTES:**
- To split outputs by line, see `@lines($(cmd))`.
- `@(cmd)` is equivalent to `@split($(cmd))`
- If not double quoted, newlines will be replaced with spaces
# Features
# Miscellaneous Features
These are features of Ion that don't belong to any specific category:
# Quoting Rules
In general, double quotes allow expansions within quoted text, whereas single quotes do not.
An exception to the rule is brace expansions, where double quotes are not allowed. When
arguments are parsed, the general rule is the replace newlines with spaces. When double-quoted
expansions will retain their newlines. Quoting rules are reversed for heredocs and for loops.
- Variables are expanded in double quotes, but not single quotes.
- Braces are expanded when unquoted, but not when quoted.
......@@ -2,7 +2,7 @@
Ion supports a universal syntax for slicing strings and arrays. For maximum language support,
strings are sliced and indexed by graphemes. Arrays are sliced and indexed by their elements.
Slicing uses the same **[]** characters as arrays, but the shell can differentation between
Slicing uses the same **[]** characters as arrays, but the shell can differentiation between
a slice and an array based on the placement of the characters (immediately after an expansion).
**NOTE:** It's important to note that indexes count from 0, as in most other languages.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment