Skip to content

Commit

Permalink
[lang0] simplify freshen -- to only take set
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed May 17, 2024
1 parent 475667d commit f8edd42
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 3 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[lang0] move `utils/freshen` to top level
[lang1] fix `freshen` -- be like lang0 with `usedNames`

# lang1

[lang1] fix `freshen` -- be like lang0 with `usedNames`
[lang1] 支持 `(assert-equal)``(assert-not-equal)`
[lang1] 支持直接递归函数与相互递归函数,不能判断等价的地方就不判断。

Expand Down
6 changes: 3 additions & 3 deletions src/lang0/utils/freshen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { test } from "node:test"
import { freshen } from "./freshen.js"

test("freshen create new string not in set", () => {
assert.deepStrictEqual(freshen(["x"], "x"), "x₁")
assert.deepStrictEqual(freshen(["x", "x₁"], "x"), "x₂")
assert.deepStrictEqual(freshen(["x", "x₁", "x₂"], "x"), "x₃")
assert.deepStrictEqual(freshen(new Set(["x"]), "x"), "x₁")
assert.deepStrictEqual(freshen(new Set(["x", "x₁"]), "x"), "x₂")
assert.deepStrictEqual(freshen(new Set(["x", "x₁", "x₂"]), "x"), "x₃")
})
5 changes: 1 addition & 4 deletions src/lang0/utils/freshen.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { stringToSubscript } from "../../utils/stringToSubscript.js"

export function freshen(
usedNames: Array<string> | Set<string>,
name: string,
): string {
export function freshen(usedNames: Set<string>, name: string): string {
usedNames = new Set(usedNames)
let counter = 1
let freshName = name
Expand Down

0 comments on commit f8edd42

Please sign in to comment.