11import { freshen } from "../../utils/name/freshen.ts"
22import { applyWithDelay } from "../evaluate/index.ts"
3+ import { formatValue } from "../format/index.ts"
34import * as Neutrals from "../value/index.ts"
45import * as Values from "../value/index.ts"
56import {
@@ -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
1316export 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