Skip to content

Commit

Permalink
update to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Feb 23, 2025
1 parent 00d4250 commit 6cdb98f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/common-concepts/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,8 @@ len(myArray)

Arrays are allocated on the stack and this is guaranteed. But they are not implemented with references and common allocations. So when an array is copied, a copy that shares the common allocation is not created. A new array is created on the stack.

The copies are not deep copy. Just allocates new stack with size of array and copies all elements with default copy semantics, not deep copy semantics.
The copies are not deep copy. Just allocates new stack with size of array and copies all elements with default copy semantics, not deep copy semantics.

### Range Iterations

Arrays can be used with range iteration. The first variable in the iteration is an integer-type index variable. This variable represents the index of the element, while the second variable is the element currently pointed to in the iteration.
12 changes: 6 additions & 6 deletions src/common-concepts/control-flow/iterations.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ fn main() {
```
The while-next iteration above executes first if the condition is met. After execution, the statement is executed. Then the scope executes if the condition is met, so on.

## Foreach Iterations
Foreach or for-each can be summarized as an iteration standard for collections. It repeats itself by looping through the elements of the collection.
## Range Iterations
Range iterations can be summarized as an iteration standard for collections. It repeats itself by looping through the elements of the collection.

Each identifier used for foreach is used to create a new variable. So if there is a definition that already has this identifier, it will be shaded.
Each identifier used for range is used to create a new variable. So if there is a definition that already has this identifier, it will be shaded.

For example:
```jule
Expand All @@ -66,10 +66,10 @@ fn main() {
// 3
// 4
```
Seen as the example at above, this is a foreach iteration.\
Seen as the example at above, this is a range iteration.\
Iterations can have two variables: Current index and current element.

This example, just shows index. Let's see foreach iteration with content.
This example, just shows index. Let's see range iteration with content.

For example:
```jule
Expand All @@ -94,7 +94,7 @@ Jule assign variables data types by automatically by collection. Similar to type

---

Foreach iterations have immutable variables by default. But you may want to get them as mutable. For this, enclose the identifiers in parentheses and qualify the variable you want to be mutable as mutable.
Range iterations have immutable variables by default. But you may want to get them as mutable. For this, enclose the identifiers in parentheses and qualify the variable you want to be mutable as mutable.

For example:
```jule
Expand Down
4 changes: 4 additions & 0 deletions src/common-concepts/maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ x := map[int]str{
}
```

### Range Iterations

Maps can be used with range iteration. The first variable in the iteration is the key variable. This variable represents the key, while the second variable is the value currently pointed to in the iteration.

## Access to Elements and Indexing
To get the value of a key, it is sufficient to index it with the key.

Expand Down
4 changes: 4 additions & 0 deletions src/common-concepts/slices.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ let x = []f64([1, 2, 3, 4, 5])

At example above, the variable `x` has the `[]f64` type.

### Range Iterations

Slices can be used with range iteration. The first variable in the iteration is an integer-type index variable. This variable represents the index of the element, while the second variable is the element currently pointed to in the iteration.

## Passing Slices to Variadic Parameter
We know that `...` is used for Variadic parameters. We also know that each variadic parameter is actually a slice.
So can we pass an slice to a variadic parameter? Yes. Again, the `...` operator is used for this.
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/compiler-optimizations.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Enabled special optimizations for the built-in append function.
Enables special optimizations for copy operations.\
It reduces copying operations whenever possible.

- Once proven safe, it reduces the cost of copying in foreach iterations. Having immutability is very effective to have this optimization.
- Once proven safe, it reduces the cost of copying in range iterations. Having immutability is very effective to have this optimization.
- Refers to data instead of copying when using lvalue in match statements.
- Converts empty string comparisons to length-is-zero checking.
- Avoids making literal wrapper for strings when strings compared with literals.
Expand Down Expand Up @@ -97,7 +97,7 @@ Enables special optimizations for memory accessing.

- Skips safety checks such as boundary checking if accessed to array via constant index expression.
- Removes the cost of boundary checking of expressions like `array[i&(len(array)-1)]` for arrays whose length is power of two.
- If in a foreach iteration the iterated variable referred to by a immutable index variable is indexed, it is optimized as direct access and the cost of safety measures such as boundary checking is bypassed. <div class="warning-badge">experimental</div>
- If in a range iteration the iterated variable referred to by a immutable index variable is indexed, it is optimized as direct access and the cost of safety measures such as boundary checking is bypassed. <div class="warning-badge">experimental</div>
- If it can be understood that the index value used in any indexing process is within the boundaries, it removes the cost of boundary checking. <div class="warning-badge">experimental</div>
- If it can be understood that the smart pointer is not nil, it removes the cost of nil dereferencing. <div class="warning-badge">experimental</div>

Expand Down Expand Up @@ -176,8 +176,8 @@ Enables special optimizations for exceptionals.
`--opt-iter`\
Enables special optimizations for iterations.

- Removes casting if non-constant string casted to byte slice for range iteration. Uses string directly.
- Removes casting if non-constant stringf cases to rune slice for range iteration. Avoids making allocation for temporary rune slice, iterates runes of string directly.
- Removes casting if non-constant string casted to byte slice for range iteration. Uses string's bytes directly.
- Removes casting if non-constant string casted to rune slice for range iteration. Avoids making allocation for temporary rune slice, iterates runes of string directly.
- Makes array the slice literal expressions of the range iterations.

---
Expand Down
4 changes: 4 additions & 0 deletions src/introduction/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ In most cases, any concatenation will result as heap allocation which is might b

It also supports the `<`, `<=`, `>`, and `>=` operators for comparing strings. But it is not case-sensitive, case-insensitive or like that. This operators just compares bytes/runes of strings.

### Range Iterations

Strings can be used with range iteration. The first variable in the iteration is an integer-type index variable. This variable represents the starting byte position of the rune based on runes (Unicode code points), while the second variable is the rune currently pointed to in the iteration.

### String Literals
```jule
"String literal of Jule."
Expand Down
2 changes: 1 addition & 1 deletion src/tools/julefmt.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Write result to (source) file instead of stdout.
- In binary expressions, if it is necessary to go to the next line, the indentation is increased only once and the following part is provided by this entry.
- If this happens in a new expression with parentheses, indentation is applied in the same way. For indentation that continues after the parentheses, the previous indentation level is used, no alignment is performed.
- If there is a shift to the bottom line in a binary expression, comments are exempt from any alignment process.
- In Foreach iterations, comments coming before key variables are considered to belong to the variables. Comments before the `in` token and expression are preserved. Follow-up comments are transferred into scope.
- In range iterations, comments coming before key variables are considered to belong to the variables. Comments before the `in` token and expression are preserved. Follow-up comments are transferred into scope.
- In match expressions, comments before the expression are preserved. Followers are transferred into the scope. If there is a case, it owns it. If it does not exist, it is added to the scope.
- Comments coming within the scope of case statements are evaluated within the scope. So, if you are going to write a comment for a case and there is a case before it, the comments are accepted within the scope of that case. Therefore, it must be written within the scope of the relevant case.
- In if statements, comments before the statement are preserved. Followers are transferred into the scope.
Expand Down

0 comments on commit 6cdb98f

Please sign in to comment.