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

:book: Update array / string pages

parent 6438446b
No related branches found
No related tags found
No related merge requests found
......@@ -47,7 +47,7 @@ let c:bool = n
echo $a $b $c
let a:str b[] c:int d:float[] = one [two three] 4 [5.1 6.2 7.3]
let a:str b[str] c:int d:float[] = one [two three] 4 [5.1 6.2 7.3]
echo $a
echo @b
echo $c
......@@ -66,16 +66,19 @@ two three
5.1 6.2 7.3
```
## Supported Types
- []
- bool
- bool[]
- float
- float[]
- int
- int[]
- str
- str[]
- hmap[]
- bmap[]
## Supported Primitive Types
- `str`: A string, the essential primitive of a shell.
- `bool`: A value which is either `true` or `false`.
- `int`: An integer is any whole number.
- `float`: A float is a rational number (fractions represented as a decimal).
## Arrays
The `[T]` type, where `T` is a primitive, is an array of that primitive type.
## Maps
Likewise, `hmap[T]` and `bmap[T]` work in a similar fashion, but are a collection
of key/value pairs, where the key is always a `str`, and the value is defined by the
`T`.
......@@ -27,13 +27,17 @@ echo $foo[7..]
echo $foo[2..9]
```
## Dropping String Variables
## String concatenation
The `drop` command may be used to drop string variables.
The `++=` and `::=` operators can be used to efficiently concatenate a string in-place.
```sh
let variable = "testing"
echo $variable
drop variable
echo $variable
let string = "ello"
let string ::= H
let string ++= ", world!"
echo $string
```
```
Hello, world!
```
......@@ -48,17 +48,31 @@ This will join each element of the array into a string, adding spaces between ea
```sh
let array = [ hello world ]
let other_array = [ this is the ion ]
let array = [ @array @other_array shell ]
let as_string = @array
echo @array
echo $array
```
```
hello world this is the ion shell
hello world this is the ion shell
```
## Array concatenation
The `++=` and `::=` operators can be used to efficient concatenate an array in-place.
The `++=` and `::=` operators can be used to efficiently concatenate an array in-place.
```sh
let array = [1 2 3]
let array ++= [5 6 7]
let array ::= 0
echo @array
```
```
0 1 2 3 4 5 6 7
```
## Expand array as arguments to a command
......@@ -70,14 +84,3 @@ individual argument, if any arguments exist.
let args = [-l -a --color]
ls @args
```
## Dropping Array Variables
The `drop -a` command will drop array variables from the shell.
```sh
let array = [one two three]
echo @array
drop -a array
echo @array
```
......@@ -48,3 +48,11 @@ echo @values(hashmap)
```
echo @hashmap
```
## Iterate key/value paris in a loop
```
for key value in @hashmap
echo $key: $value
end
```
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