You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Many typo/grammar fixes and clarification improvements
* Replaced the old pre-Julia-1.0 style iterator interface shown in the
"internals" page with the correct `iterate` interface that's actually
used by the package
* Fix install instructions to import `Pkg` first, and sync the authors
list with what's in the README
Copy file name to clipboardExpand all lines: docs/src/index.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# ResumableFunctions
2
2
3
-
C# style generators a.k.a. semi-coroutines for Julia.
3
+
*C# style generators a.k.a. semi-coroutines for Julia.*
4
4
5
5
C# has a convenient way to create iterators using the `yield return` statement. The package `ResumableFunctions` provides the same functionality for the Julia language by introducing the `@resumable` and the `@yield` macros. These macros can be used to replace the `Task` switching functions `produce` and `consume` which were deprecated in Julia v0.6. `Channels` are the preferred way for inter-task communication in julia v0.6+, but their performance is subpar for iterator applications.
6
6
@@ -40,12 +40,14 @@ end
40
40
41
41
`ResumableFunctions` is a registered package and can be installed by running:
42
42
```julia
43
+
using Pkg
43
44
Pkg.add("ResumableFunctions")
44
45
```
45
46
46
47
## Authors
47
48
48
49
* Ben Lauwens, Royal Military Academy, Brussels, Belgium.
Copy file name to clipboardExpand all lines: docs/src/internals.md
+45-34Lines changed: 45 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,16 @@
1
1
# Internals
2
2
3
-
The macro `@resumable` transform a function definition into a finite state-machine, i.e. a callable type holding the state and references to the internal variables of the function and a constructor for this new type respecting the method signature of the original function definition. When calling the new type a modified version of the body of the original function definition is executed:
4
-
- a dispatch mechanism is inserted at the start to allow a non local jump to a label inside the body;
5
-
- the `@yield` statement is replaced by a `return` statement and a label placeholder as endpoint of a non local jump;
6
-
-`for` loops are transformed in `while` loops and
7
-
-`try`-`catch`-`finally`-`end` expressions are converted in a sequence of `try`-`catch`-`end` expressions with at the end of the `catch` part a non local jump to a label that marks the beginning of the expressions in the `finally` part.
8
-
The two last transformations are needed to overcome the limitations of the non local jump macros `@goto` and `@label`.
3
+
The macro `@resumable` transforms a function definition into a finite state-machine, i.e.
4
+
* a callable type holding the state and references to the internal variables of the function, and
5
+
* a constructor for this new type respecting the method signature of the original function definition.
6
+
7
+
When calling an instance of this new type, a modified version of the body of the original function definition is executed:
8
+
- a dispatch mechanism is inserted at the start to allow a non-local jump to a label inside the body;
9
+
- the `@yield` statement is replaced by a `return` statement and a label placeholder as endpoint of a non-local jump;
10
+
-`for` loops are transformed into `while` loops; and
11
+
-`try`-`catch`-`finally`-`end` expressions are converted into a sequence of `try`-`catch`-`end` expressions; at the end of the `catch` part, a non-local jump is inserted to a label that marks the beginning of the expressions in the `finally` part.
12
+
13
+
The last two transformations are needed to overcome the limitations of the non-local jump macros `@goto` and `@label`.
9
14
10
15
The complete procedure is explained using the following example:
11
16
@@ -27,18 +32,19 @@ The function definition is split by `MacroTools.splitdef` in different parts, eg
27
32
28
33
## For loops
29
34
30
-
`for` loops in the body of the function definition are transformed in equivalent while loops:
35
+
`for` loops in the body of the function definition are transformed into equivalent `while` loops:
A call function is constructed that creates the previously defined composite type. This function satisfy the calling convention of the original function definition and is returned from the macro:
90
+
A caller function is constructed that creates the previously defined composite type. This function satisfies the calling convention of the original function definition and is returned from the macro:
85
91
86
92
```julia
87
93
functionfibonacci(n::Int)
@@ -93,7 +99,7 @@ end
93
99
94
100
## Transformation of the body
95
101
96
-
In 6 steps the body of the function definition is transformed into a finite state-machine.
102
+
In 6 steps the body of the function definition is transformed into a finite state-machine:
`try`-`catch`-`finally`-`end` expressions are converted in a sequence of `try`-`catch`-`end` expressions with at the end of the `catch` part a nonlocal jump to a label that marks the beginning of the expressions in the `finally` part.
156
+
`try`-`catch`-`finally`-`end` expressions are converted into a sequence of `try`-`catch`-`end` expressions; at the end of the `catch` part, a non-local jump is inserted to a label that marks the beginning of the expressions in the `finally` part.
149
157
150
158
### Yield transformation
151
159
152
-
The `@yield` statement is replaced by a `return` statement and a label placeholder as endpoint of a nonlocal jump:
160
+
The `@yield` statement is replaced by a `return` statement and a label placeholder as target of a non-local jump:
Copy file name to clipboardExpand all lines: docs/src/manual.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -188,7 +188,7 @@ ERROR: @resumable function has stopped!
188
188
DocTestSetup = nothing
189
189
```
190
190
191
-
When the `@resumable function` returns normally an error will be thrown if called again.
191
+
When the `@resumable function` returns normally (i.e. at the end of the function rather than at a `@yield` point), an error will be thrown if called again.
192
192
193
193
## Two-way communication
194
194
@@ -320,7 +320,7 @@ DocTestSetup = nothing
320
320
321
321
## Parametric `@resumable` functions
322
322
323
-
Type parameters can be specified with a `where` clause:
323
+
Type parameters can be specified with a normal Julia `where` clause:
0 commit comments