Skip to content

Commit 2132ffb

Browse files
authored
Merge pull request #61 from DanexCodr/copilot/implement-lambda-recursion-syntax
Enforce ALL_CAPS constant semantics and add `<~CONST(...)` self-call level support
2 parents 444b80e + e78eb7d commit 2132ffb

23 files changed

Lines changed: 898 additions & 212 deletions

source_.jar

5.25 KB
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
unit test
2+
3+
share AutoCurrying {
4+
share main() {
5+
sum := [1, 2, 3, 4].reduce(\(acc) \(value) acc + value, 0)
6+
out("sum=" + sum)
7+
8+
withIndex := [5, 6, 7].reduce(\(acc) \(value) \(idx) acc + value + idx, 0)
9+
out("withIndex=" + withIndex)
10+
11+
classic := [1, 2, 3, 4].reduce(\(acc, value) acc + value, 0)
12+
out("classic=" + classic)
13+
}
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
unit test
2+
3+
share ConstantReassignmentInvalid {
4+
share main() {
5+
LIMIT := 5
6+
LIMIT = 6
7+
out(LIMIT)
8+
}
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
unit test
2+
3+
share ConstantRequiresInitializerInvalid {
4+
share main() {
5+
LIMIT: int
6+
out(LIMIT)
7+
}
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
unit test
2+
3+
share SelfCallInvalidNoParentheses {
4+
local bad(n: int) :: result: int {
5+
~> result: <~ + n
6+
}
7+
8+
share main() {
9+
out([result]:bad(1))
10+
}
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
unit test
2+
3+
share SelfCallLambda {
4+
share main() {
5+
n := 6
6+
recursiveResult := 0
7+
recursiveResult = [result]:\(n: int) :: result: int {
8+
if n <= 1 {
9+
~> result: 1
10+
}
11+
~> result: n * <~(n - 1)
12+
}
13+
14+
out("lambda=" + recursiveResult)
15+
}
16+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
unit test
2+
3+
share SelfCallLambdaConstantLevel {
4+
share main() {
5+
SELF := 0
6+
PARENT := 1
7+
8+
a := 2
9+
result := 0
10+
result = [result]:\(a: int) :: result: int {
11+
if a <= 0 {
12+
~> result: 0
13+
}
14+
15+
b := a
16+
inner := 0
17+
inner = [result]:\(b: int) :: result: int {
18+
if b <= 0 {
19+
~> result: 0
20+
}
21+
22+
same := <~SELF(b - 1)
23+
up := <~PARENT(b - 1)
24+
~> result: b + same + up
25+
}
26+
27+
~> result: inner
28+
}
29+
30+
out("const-level=" + result)
31+
}
32+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
unit test
2+
3+
share SelfCallLambdaLevels {
4+
share main() {
5+
a := 2
6+
levels := 0
7+
levels = [result]:\(a: int) :: result: int {
8+
if a <= 0 {
9+
~> result: 0
10+
}
11+
12+
b := a
13+
mid := 0
14+
mid = [result]:\(b: int) :: result: int {
15+
if b <= 0 {
16+
~> result: 0
17+
}
18+
19+
c := b
20+
inner := 0
21+
inner = [result]:\(c: int) :: result: int {
22+
if c <= 0 {
23+
~> result: 0
24+
}
25+
26+
selfShortcut := <~(c - 1)
27+
selfExplicit := <~0(c - 1)
28+
parent := <~1(c - 1)
29+
grandparent := <~2(c - 1)
30+
31+
~> result: c + selfShortcut + selfExplicit + parent + grandparent
32+
}
33+
34+
~> result: inner
35+
}
36+
37+
~> result: mid
38+
}
39+
40+
out("levels=" + levels)
41+
}
42+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
unit test
2+
3+
share SelfCallLevelConstantInMethodInvalid {
4+
local bad(n: int) :: result: int {
5+
LEVEL := 0
6+
if n < 2 {
7+
~> result: 1
8+
}
9+
~> result: n * <~LEVEL(n - 1)
10+
}
11+
12+
share main() {
13+
out([result]:bad(4))
14+
}
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
unit test
2+
3+
share SelfCallLevelInMethodInvalid {
4+
local bad(n: int) :: result: int {
5+
if n < 2 {
6+
~> result: 1
7+
}
8+
~> result: n * <~0(n - 1)
9+
}
10+
11+
share main() {
12+
out([result]:bad(4))
13+
}
14+
}

0 commit comments

Comments
 (0)