-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reuse beta-reduction logic from BetaReduce
Fixes a bug when beta-reducing inlined code. In some situations the beta-reduction did not bind mutable variables.
- Loading branch information
1 parent
c9ace66
commit e0ac044
Showing
5 changed files
with
43 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
inline def cfor(inline body: Int => Unit): Unit = | ||
var index = 0 | ||
while index < 3 do | ||
body(index) | ||
index = index + 1 | ||
|
||
@main def Test = | ||
assert(test1() == test2(), (test1(), test2())) | ||
|
||
def test1() = | ||
val b = collection.mutable.ArrayBuffer.empty[() => Int] | ||
cfor { x => | ||
b += (() => x) | ||
} | ||
b.map(_.apply()).toList | ||
|
||
def test2() = | ||
val b = collection.mutable.ArrayBuffer.empty[() => Int] | ||
var index = 0 | ||
while index < 3 do | ||
((x: Int) => b += (() => x)).apply(index) | ||
index = index + 1 | ||
b.map(_.apply()).toList |