Skip to content

Commit 71e4ec0

Browse files
committed
up
1 parent 9a664a7 commit 71e4ec0

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

src/lang/same/Ctx.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
export type Ctx = {
22
boundNames: Set<string>
3+
depth: number
34
}
45

56
export function emptyCtx(): Ctx {
67
return {
78
boundNames: new Set(),
9+
depth: 0,
10+
}
11+
}
12+
13+
export function ctxDepthAdd1(ctx: Ctx): Ctx {
14+
return {
15+
...ctx,
16+
depth: ctx.depth + 1,
817
}
918
}
1019

src/lang/same/sameInCtx.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { freshen } from "../../utils/name/freshen.ts"
22
import { applyWithDelay } from "../evaluate/index.ts"
3+
import { formatValue } from "../format/index.ts"
34
import * as Neutrals from "../value/index.ts"
45
import * as Values from "../value/index.ts"
56
import {
@@ -8,12 +9,21 @@ import {
89
type Neutral,
910
type Value,
1011
} from "../value/index.ts"
11-
import { ctxBindName, type Ctx } from "./Ctx.ts"
12+
import { ctxBindName, ctxDepthAdd1, type Ctx } from "./Ctx.ts"
13+
14+
const debug = false
1215

1316
export function sameInCtx(ctx: Ctx, lhs: Value, rhs: Value): boolean {
17+
ctx = ctxDepthAdd1(ctx)
18+
1419
lhs = Values.lazyActiveDeep(lhs)
1520
rhs = Values.lazyActiveDeep(rhs)
1621

22+
if (debug) {
23+
console.log("[sameInCtx]", ctx.depth, " ", formatValue(lhs))
24+
console.log("[sameInCtx]", ctx.depth, "=", formatValue(rhs))
25+
}
26+
1727
if (lhs.kind === "NotYet" && rhs.kind === "NotYet") {
1828
return sameNeutralInCtx(ctx, lhs.neutral, rhs.neutral)
1929
}
@@ -51,18 +61,16 @@ export function sameInCtx(ctx: Ctx, lhs: Value, rhs: Value): boolean {
5161
}
5262
}
5363

54-
if (
55-
lhs.kind === "DelayedApply" &&
56-
!(lhs.target.kind === "Lambda" && lambdaIsDefined(lhs.target))
57-
) {
58-
return sameInCtx(ctx, applyWithDelay(lhs.target, lhs.arg), rhs)
64+
if (lhs.kind === "DelayedApply") {
65+
if (!(lhs.target.kind === "Lambda" && lambdaIsDefined(lhs.target))) {
66+
return sameInCtx(ctx, applyWithDelay(lhs.target, lhs.arg), rhs)
67+
}
5968
}
6069

61-
if (
62-
rhs.kind === "DelayedApply" &&
63-
!(rhs.target.kind === "Lambda" && lambdaIsDefined(rhs.target))
64-
) {
65-
return sameInCtx(ctx, lhs, applyWithDelay(rhs.target, rhs.arg))
70+
if (rhs.kind === "DelayedApply") {
71+
if (!(rhs.target.kind === "Lambda" && lambdaIsDefined(rhs.target))) {
72+
return sameInCtx(ctx, lhs, applyWithDelay(rhs.target, rhs.arg))
73+
}
6674
}
6775

6876
return false

0 commit comments

Comments
 (0)