firefly-compiler 0.4.82 → 0.4.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -58,7 +58,7 @@ swap[A, B](pair: Pair[A, B]): Pair[B, A] {
|
|
|
58
58
|
}
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
Two type parameters `A` and `B` are first introduced in the square brackets. These type parameters are swapped in the input and return type, expressing the value swap at type level. The type parameters are
|
|
61
|
+
Two type parameters `A` and `B` are first introduced in the square brackets. These type parameters are swapped in the input and return type, expressing the value swap at type level. The type parameters are unbounded in the sense that `swap` may be called with `A` and `B` replaced by any types.
|
|
62
62
|
|
|
63
63
|
Type parameters can be bounded or constrained like this:
|
|
64
64
|
|
|
@@ -104,13 +104,13 @@ add(a: Int, b: Int = 1): Int {
|
|
|
104
104
|
When called without the second arguments, the function will use the default value:
|
|
105
105
|
|
|
106
106
|
```firefly
|
|
107
|
-
|
|
107
|
+
add(1) // returns 2
|
|
108
108
|
```
|
|
109
109
|
|
|
110
110
|
If an argument is provided, it overrides the default:
|
|
111
111
|
|
|
112
112
|
```firefly
|
|
113
|
-
|
|
113
|
+
add(1, 2) // returns 3
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
|
|
@@ -132,7 +132,7 @@ When calling `factorial(0)`, the base case is triggered, returning `1`. Calling
|
|
|
132
132
|
|
|
133
133
|
# Tail Recursion
|
|
134
134
|
|
|
135
|
-
In some recursive functions, the recursive call is the last operation performed before returning the result. This is
|
|
135
|
+
In some recursive functions, the recursive call is the last operation performed before returning the result. This is _tail recursion_. The Firefly compiler can optimize tail recursive calls, avoiding the buildup of function calls on the stack.
|
|
136
136
|
|
|
137
137
|
You can use the `tailcall` keyword to explicitly mark a recursive call as tail-recursive, ensuring the compiler applies the optimization.
|
|
138
138
|
|
|
@@ -164,13 +164,12 @@ In firefly anonymous functions are written in curlybrases and constucted like th
|
|
|
164
164
|
This anonymous function takes two arguments and returns their sum. Like named functions, the body is a sequence of statements where the last expression is returned.
|
|
165
165
|
|
|
166
166
|
Anonymous functions are often used right away, like below:
|
|
167
|
-
:
|
|
168
167
|
|
|
169
168
|
```firefly
|
|
170
169
|
[1, 2, 3].map({x => x + 1}) // Returns [2, 3, 4]
|
|
171
170
|
```
|
|
172
171
|
|
|
173
|
-
An anonymous function that increments the given value by one is passed as argument to the
|
|
172
|
+
An anonymous function that increments the given value by one is passed as argument to the method `map` working on lists.
|
|
174
173
|
|
|
175
174
|
These functions are anonymous in the sense that they do not bring a name into scope themselves. They are just expressions that construct a function value. Like all other values, they can be assigned to variables, passed as arguments, or returned from other functions. But unlike other values, they can also be called.
|
|
176
175
|
|
|
@@ -200,7 +199,7 @@ This is an anonymous function taking no arguments and returning `Unit`:
|
|
|
200
199
|
let unit: () => Unit = {}
|
|
201
200
|
```
|
|
202
201
|
|
|
203
|
-
This is an anonymous function that increments its input:
|
|
202
|
+
This is an anonymous function that increments its input by one:
|
|
204
203
|
|
|
205
204
|
```firefly
|
|
206
205
|
let next: Int => Int = {i => i + 1}
|
package/package.json
CHANGED
package/vscode/package.json
CHANGED