Commit 65947555 authored by Michael Aaron Murphy's avatar Michael Aaron Murphy
Browse files

Document New Assignment Logic

parent dc9e0f15
......@@ -16,10 +16,9 @@
- [Variable Assignments](ch04-00-variables.md)
- [String Variables](ch04-01-strings.md)
- [Tuple Variables](ch04-02-tuples.md)
- [Array Variables](ch04-03-arrays.md)
- [Arithmetic Variables](ch04-04-arithmetic.md)
- [Exporting Variables](ch04-05-exporting.md)
- [Array Variables](ch04-02-arrays.md)
- [Arithmetic Variables](ch04-03-arithmetic.md)
- [Exporting Variables](ch04-04-exporting.md)
- [Expansions](ch05-00-expansions.md)
......
......@@ -4,3 +4,76 @@ The `let` builtin is used to create local variables within the shell, and apply
to variables. The `export` keyword may be used to do the same for the creation of external
variables. Variables cannot be created the POSIX way, as the POSIX way is awkard to read/write
and parse.
```ion
let string_variable = "hello string"
let array_variable = [ hello array ]
```
## Multiple Assignments
Ion also supports setting multiple values at the same time
```ion
let a b = one two
echo $a
echo $b
let a b = one [two three four]
echo $a
echo @b
```
#### Output
```
one
two
one
two three four
```
## Type-Checked Assignments
It's also possible to designate the type that a variable is allowed to be initialized with.
Boolean type assignments will also normalize inputs into either `true` or `false`. When an
invalid value is supplied, the assignment operation will fail and an error message will be
printed. All assignments after the failed assignment will be ignored.
```ion
let a:bool = 1
let b:bool = true
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]
echo $a
echo @b
echo $c
echo @d
```
#### Output
```
true
true
false
one
two three
4
5.1 6.2 7.3
```
## Supported Types
- []
- bool
- bool[]
- float
- float[]
- int
- int[]
- str
- str[]
# Tuple Assignments
Ion also supports assigning multiple variables at once, which can increase readability and save
some precious CPU cycles. The general trend is that the less statements that you execute, the
faster your scripts will execute, but there are some exceptions to the rule -- see the general
tips in the miscellanious section. In addition to assigning multiple variables, this can also
be used to swap variables.
```ion
let a b = 1 2
let a b = [1 2]
let a b = [$b $a]
```
Do note, however, that if you supply too many values, they will be ignored.
```ion
$ let a b = 1 2 3
$ echo $a $b
> 1 2
```
......@@ -10,8 +10,12 @@ Operators currently supported are:
- [x] Divide (**/**)
- [ ] Integer Divide (**//**)
- [ ] Modulus (**%**)
- [ ] Powers (not stabilized yet: **^**; subject to change to **\*\***)
- [x] Powers (**\*\***)
## Individual Assignments
The following examples are a demonstration of applying a mathematical operation to an individual
variable -- first assigning `0` to the variable, then applying arithmetic operations to it.
```ion
let value = 0
......@@ -21,3 +25,21 @@ let value *= 3
let value /= 2
```
## Multiple Assignments
It's also possible to perform a mathematical operation to multiple variables. Each variable will be
designated with a paired value.
```ion
let a b = 5 5
let a b += 3 2
let a b -= 1 1
echo $a $b
```
This will output the following:
```
7 6
```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment