Skip to content

Commit 96a100c

Browse files
committed
up
1 parent c07ae4c commit 96a100c

File tree

4 files changed

+56
-64
lines changed

4 files changed

+56
-64
lines changed

src/lang/equal/equal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { type Value } from "../value/index.ts"
22
import { emptyCtx } from "./Ctx.ts"
33
import { equalInCtx } from "./equalInCtx.ts"
44

5-
export function equal(left: Value, right: Value): boolean {
6-
return equalInCtx(emptyCtx(), left, right)
5+
export function equal(lhs: Value, rhs: Value): boolean {
6+
return equalInCtx(emptyCtx(), lhs, rhs)
77
}

src/lang/equal/equalInCtx.ts

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,68 +15,60 @@ import {
1515

1616
const debug = false
1717

18-
export function equalInCtx(ctx: Ctx, left: Value, right: Value): boolean {
18+
export function equalInCtx(ctx: Ctx, lhs: Value, rhs: Value): boolean {
1919
ctx = ctxDepthAdd1(ctx)
2020

21-
left = Values.lazyActiveDeep(left)
22-
right = Values.lazyActiveDeep(right)
21+
lhs = Values.lazyActiveDeep(lhs)
22+
rhs = Values.lazyActiveDeep(rhs)
2323

2424
if (debug) {
25-
console.log("[equalInCtx]", ctx.depth, " ", formatValue(left))
26-
console.log("[equalInCtx]", ctx.depth, "=", formatValue(right))
27-
console.log("[equalInCtx]", "same:", same(left, right))
25+
console.log("[equalInCtx]", ctx.depth, " ", formatValue(lhs))
26+
console.log("[equalInCtx]", ctx.depth, "=", formatValue(rhs))
27+
console.log("[equalInCtx]", "same:", same(lhs, rhs))
2828
}
2929

30-
if (same(left, right)) return true
30+
if (same(lhs, rhs)) return true
3131

32-
if (left.kind === "NotYet" && right.kind === "NotYet") {
33-
return equalNeutralInCtx(ctx, left.neutral, right.neutral)
32+
if (lhs.kind === "NotYet" && rhs.kind === "NotYet") {
33+
return equalNeutralInCtx(ctx, lhs.neutral, rhs.neutral)
3434
}
3535

36-
if (left.kind === "Lambda") {
37-
if (lambdaIsDefined(left)) {
38-
if (ctxBlazeOccurred(ctx, left, right)) {
36+
if (lhs.kind === "Lambda") {
37+
if (lambdaIsDefined(lhs)) {
38+
if (ctxBlazeOccurred(ctx, lhs, rhs)) {
3939
return true
4040
} else {
41-
ctx = ctxBlazeTrail(ctx, left, right)
41+
ctx = ctxBlazeTrail(ctx, lhs, rhs)
4242
}
4343
}
4444

45-
const freshName = freshen(ctx.boundNames, left.name)
45+
const freshName = freshen(ctx.boundNames, lhs.name)
4646
ctx = ctxBindName(ctx, freshName)
4747
const v = Neutrals.Var(freshName)
4848
const arg = Values.NotYet(v)
49-
return equalInCtx(
50-
ctx,
51-
applyWithDelay(left, arg),
52-
applyWithDelay(right, arg),
53-
)
49+
return equalInCtx(ctx, applyWithDelay(lhs, arg), applyWithDelay(rhs, arg))
5450
}
5551

56-
if (right.kind === "Lambda") {
57-
if (lambdaIsDefined(right)) {
58-
if (ctxBlazeOccurred(ctx, right, left)) {
52+
if (rhs.kind === "Lambda") {
53+
if (lambdaIsDefined(rhs)) {
54+
if (ctxBlazeOccurred(ctx, rhs, lhs)) {
5955
return true
6056
} else {
61-
ctx = ctxBlazeTrail(ctx, right, left)
57+
ctx = ctxBlazeTrail(ctx, rhs, lhs)
6258
}
6359
}
6460

65-
const freshName = freshen(ctx.boundNames, right.name)
61+
const freshName = freshen(ctx.boundNames, rhs.name)
6662
ctx = ctxBindName(ctx, freshName)
6763
const v = Neutrals.Var(freshName)
6864
const arg = Values.NotYet(v)
69-
return equalInCtx(
70-
ctx,
71-
applyWithDelay(left, arg),
72-
applyWithDelay(right, arg),
73-
)
65+
return equalInCtx(ctx, applyWithDelay(lhs, arg), applyWithDelay(rhs, arg))
7466
}
7567

76-
if (left.kind === "DelayedApply" && right.kind === "DelayedApply") {
68+
if (lhs.kind === "DelayedApply" && rhs.kind === "DelayedApply") {
7769
if (
78-
equalInCtx(ctx, left.target, right.target) &&
79-
equalInCtx(ctx, left.arg, right.arg)
70+
equalInCtx(ctx, lhs.target, rhs.target) &&
71+
equalInCtx(ctx, lhs.arg, rhs.arg)
8072
) {
8173
return true
8274
}
@@ -94,12 +86,12 @@ export function equalInCtx(ctx: Ctx, left: Value, right: Value): boolean {
9486
// }
9587
}
9688

97-
if (left.kind === "DelayedApply") {
98-
return equalInCtx(ctx, applyWithDelay(left.target, left.arg), right)
89+
if (lhs.kind === "DelayedApply") {
90+
return equalInCtx(ctx, applyWithDelay(lhs.target, lhs.arg), rhs)
9991
}
10092

101-
if (right.kind === "DelayedApply") {
102-
return equalInCtx(ctx, left, applyWithDelay(right.target, right.arg))
93+
if (rhs.kind === "DelayedApply") {
94+
return equalInCtx(ctx, lhs, applyWithDelay(rhs.target, rhs.arg))
10395
}
10496

10597
return false

src/lang/same/same.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { type Value } from "../value/index.ts"
22
import { emptyCtx } from "./Ctx.ts"
33
import { sameInCtx } from "./sameInCtx.ts"
44

5-
export function same(left: Value, right: Value): boolean {
6-
return sameInCtx(emptyCtx(), left, right)
5+
export function same(lhs: Value, rhs: Value): boolean {
6+
return sameInCtx(emptyCtx(), lhs, rhs)
77
}

src/lang/same/sameInCtx.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,63 @@ import {
1010
} from "../value/index.ts"
1111
import { ctxBindName, type Ctx } from "./Ctx.ts"
1212

13-
export function sameInCtx(ctx: Ctx, left: Value, right: Value): boolean {
14-
left = Values.lazyActiveDeep(left)
15-
right = Values.lazyActiveDeep(right)
13+
export function sameInCtx(ctx: Ctx, lhs: Value, rhs: Value): boolean {
14+
lhs = Values.lazyActiveDeep(lhs)
15+
rhs = Values.lazyActiveDeep(rhs)
1616

17-
if (left.kind === "NotYet" && right.kind === "NotYet") {
18-
return sameNeutralInCtx(ctx, left.neutral, right.neutral)
17+
if (lhs.kind === "NotYet" && rhs.kind === "NotYet") {
18+
return sameNeutralInCtx(ctx, lhs.neutral, rhs.neutral)
1919
}
2020

21-
if (left.kind === "Lambda" && right.kind === "Lambda") {
22-
if (lambdaSameDefined(left, right)) {
21+
if (lhs.kind === "Lambda" && rhs.kind === "Lambda") {
22+
if (lambdaSameDefined(lhs, rhs)) {
2323
return true
2424
}
2525
}
2626

27-
if (left.kind === "Lambda" && !lambdaIsDefined(left)) {
28-
if (right.kind === "Lambda" && lambdaIsDefined(right)) {
27+
if (lhs.kind === "Lambda" && !lambdaIsDefined(lhs)) {
28+
if (rhs.kind === "Lambda" && lambdaIsDefined(rhs)) {
2929
return false
3030
}
3131

32-
const freshName = freshen(ctx.boundNames, left.name)
32+
const freshName = freshen(ctx.boundNames, lhs.name)
3333
ctx = ctxBindName(ctx, freshName)
3434
const arg = Values.NotYet(Neutrals.Var(freshName))
35-
return sameInCtx(ctx, applyWithDelay(left, arg), applyWithDelay(right, arg))
35+
return sameInCtx(ctx, applyWithDelay(lhs, arg), applyWithDelay(rhs, arg))
3636
}
3737

38-
if (right.kind === "Lambda" && !lambdaIsDefined(right)) {
39-
if (left.kind === "Lambda" && lambdaIsDefined(left)) {
38+
if (rhs.kind === "Lambda" && !lambdaIsDefined(rhs)) {
39+
if (lhs.kind === "Lambda" && lambdaIsDefined(lhs)) {
4040
return false
4141
}
4242

43-
const freshName = freshen(ctx.boundNames, right.name)
43+
const freshName = freshen(ctx.boundNames, rhs.name)
4444
ctx = ctxBindName(ctx, freshName)
4545
const arg = Values.NotYet(Neutrals.Var(freshName))
46-
return sameInCtx(ctx, applyWithDelay(left, arg), applyWithDelay(right, arg))
46+
return sameInCtx(ctx, applyWithDelay(lhs, arg), applyWithDelay(rhs, arg))
4747
}
4848

49-
if (left.kind === "DelayedApply" && right.kind === "DelayedApply") {
49+
if (lhs.kind === "DelayedApply" && rhs.kind === "DelayedApply") {
5050
if (
51-
sameInCtx(ctx, left.target, right.target) &&
52-
sameInCtx(ctx, left.arg, right.arg)
51+
sameInCtx(ctx, lhs.target, rhs.target) &&
52+
sameInCtx(ctx, lhs.arg, rhs.arg)
5353
) {
5454
return true
5555
}
5656
}
5757

5858
if (
59-
left.kind === "DelayedApply" &&
60-
!(left.target.kind === "Lambda" && lambdaIsDefined(left.target))
59+
lhs.kind === "DelayedApply" &&
60+
!(lhs.target.kind === "Lambda" && lambdaIsDefined(lhs.target))
6161
) {
62-
return sameInCtx(ctx, applyWithDelay(left.target, left.arg), right)
62+
return sameInCtx(ctx, applyWithDelay(lhs.target, lhs.arg), rhs)
6363
}
6464

6565
if (
66-
right.kind === "DelayedApply" &&
67-
!(right.target.kind === "Lambda" && lambdaIsDefined(right.target))
66+
rhs.kind === "DelayedApply" &&
67+
!(rhs.target.kind === "Lambda" && lambdaIsDefined(rhs.target))
6868
) {
69-
return sameInCtx(ctx, left, applyWithDelay(right.target, right.arg))
69+
return sameInCtx(ctx, lhs, applyWithDelay(rhs.target, rhs.arg))
7070
}
7171

7272
return false

0 commit comments

Comments
 (0)