documentation updates to reflect removal of the let keyword

also some general cleanups and improvements
This commit is contained in:
りき萌 2025-06-30 23:54:50 +02:00
parent 731046d1f7
commit bc2df73487
2 changed files with 125 additions and 67 deletions

View file

@ -25,8 +25,6 @@ Operators may have one or two arguments, where one argument corresponds to a pre
Note that this documentation lists a unary and binary operator of the same spelling as _two separate functions_, not overloads of a single function.
The argument name usually does not matter when calling the function - it is only used for documentation purposes.
The one exception is arguments called `...`, which signify that zero or more arguments can be passed to the function at that position.
(Currently there are no functions that accept any number of arguments, though.)
The argument _type_ however is important.
If you try to use a function with the wrong type of value as its argument, it will fail with an error.
@ -567,7 +565,7 @@ For example, consider multiplicatively blending two colors.
```haku
-- This is how you can multiply two colors together.
-- Note that the `*` operator works for colors, so you don't need to define this in your brushes.
mulRgba = \a, b ->
mulRgba: \a, b ->
rgba (rgbaR a * rgbaR b) (rgbaG a * rgbaG b) (rgbaB a * rgbaB b) (rgbaA a * rgbaA b)
```
@ -575,11 +573,11 @@ If haku represented colors using an 8-bit `0` to `255` range instead, to multipl
```haku
-- NOTE: This example does NOT work correctly.
mulRgba = \a, b ->
let red = (rgbaR a * rgbaR b) / 255
let green = (rgbaG a * rgbaG b) / 255
let blue = (rgbaB a * rgbaB b) / 255
let alpha = (rgbaA a * rgbaA b) / 255
mulRgba: \a, b ->
red = (rgbaR a * rgbaR b) / 255
green = (rgbaG a * rgbaG b) / 255
blue = (rgbaB a * rgbaB b) / 255
alpha = (rgbaA a * rgbaA b) / 255
rgba red green blue alpha
```
@ -683,32 +681,38 @@ Some of these operations may be a bit confusing, so here are some examples.
```haku
-- To add two to all elements in a list:
list = range 1 4 -- [1, 2, 3, 4]
twoAdded = map list \x ->
list: range 1 4 -- [1, 2, 3, 4]
twoAdded: map list \x ->
x + 2
-- [3, 4, 5, 6]
```
```haku
-- To filter out only even numbers in a list:
list = range 1 10
isEven = \x -> mod x 2 == 0
onlyEven = filter list isEven
list: range 1 10 -- [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
isEven: \x -> mod x 2 == 0
onlyEven: filter list isEven
-- [2, 4, 6, 8, 10]
```
```haku
-- To sum all the numbers in a list:
list = [1, 3, 10, 2, 30, 4, 1]
sum = reduce list 0 \acc, value -> acc + value
list: [1, 3, 10, 2, 30, 4, 1]
sum: reduce list 0 \acc, value -> acc + value
-- 51
```
```haku
-- To flatten a singly-nested list:
list = [[1, 2], [3, 4], [5, 6]]
flatList = flatten list -- [1, 2, 3, 4, 5, 6]
list: [[1, 2], [3, 4], [5, 6]]
flatList: flatten list -- [1, 2, 3, 4, 5, 6]
-- Note that this only applies to a single level of nesting:
deepList = [[[1, 2, 3, 4]]]
lessDeepList = flatten deepList -- [[1, 2, 3, 4]]
deepList: [[[1, 2, 3, 4]]]
lessDeepList: flatten deepList -- [[1, 2, 3, 4]]
-- This can be used to join lists together without nesting:
join: \a, b -> flatten [a, b]
```