post review fixes

This commit is contained in:
damirka 2021-07-05 15:47:01 +03:00
parent ad823ae8eb
commit f4e270ffd2

View File

@ -22,8 +22,8 @@ This proposal suggests adding countdown loops and inclusive loop ranges into Leo
# Motivation
In the current design of the language only incremental ranges are allowed. Though
in some cases there's a need for loops going in reverse direction. This example
demonstrates bubble sort algorithm where countdown loops are mocked:
in some cases there's a need for loops going in the reverse direction. This example
demonstrates the bubble sort algorithm where countdown loops are mocked:
```ts
function bubble_sort(mut a: [u32; 10]) -> [u32; 10] {
@ -40,12 +40,12 @@ function bubble_sort(mut a: [u32; 10]) -> [u32; 10] {
}
```
Having countdown loop in the example above could improve readability and
Having a countdown loop in the example above could improve readability and
usability of the language by making it more natural to the developer.
However, if we imagined this example using countdown loop, we would see that
it wouldn't be possible to count to 0; because first bound of the range is
inclusive and second is exclusive, and loops ranges must use only unsigned integers.
However, if we imagined this example using a countdown loop, we would see that
it wouldn't be possible to count to 0; because the first bound of the range is
inclusive and the second is exclusive, and loops ranges must use only unsigned integers.
```ts
// loop goes 0,1,2,3,4,5,6,7,8
@ -57,7 +57,7 @@ for i in 9..0 { /* ... */ }
Hence direct implementation of the coundown loop ranges would create asymmetry (1)
and would not allow loops to count down to 0 (2). To implement coundown loops and
solve these two problems we suggest adding inclusive range bounds.
solve these two problems we suggest adding an inclusive range bounds.
# Design
@ -73,9 +73,9 @@ for i in 5..0 {}
## Inclusive ranges
To solve loop asymmetry and to improve loop ranges in general we suggest adding
inclusive range operator to Leo. Inclusive range would extend second bound of the
loop making it inclusive (instead of default - exclusive) therefore allowing
countdown loops to reach 0 value.
inclusive range operator to Leo. Inclusive range would extend the second bound
of the loop making it inclusive (instead of default - exclusive)
therefore allowing countdown loops to reach 0 value.
```ts
// default loop: 0,1,2,3,4