Skip to content

Commit cb83089

Browse files
committed
ユーザー定義関数の使い方について説明を修正しました。
1 parent 99a912e commit cb83089

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@
6666
- `Function`を作成して、`plugin`で登録してください。
6767
6868
```
69-
val calc = Calculator()
70-
calc.plugin(Function("f(x,y)", arrayOf("x + y")))
71-
calc.eval("f(3,4)")
72-
println(calc.value)
73-
74-
結果は、 7 です。
69+
val value = Calculator()
70+
.plugin(Function("f(x)", arrayOf("x + 1")))
71+
.plugin(Function("g(x,y)", arrayOf("f(x) * y")))
72+
.eval("g(3,4)")
73+
.value
74+
println(value)
75+
76+
結果は、 16 です。
7577
```
7678
7779
## 計算可能な数式

src/test/kotlin/xyz/javecs/tools/expr/test/kotlin/CalculatorPluginTest.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ class CalculatorPluginTest {
1313
}
1414

1515
@Test fun plugin2() {
16-
val calc = Calculator()
17-
.plugin(Function("f(x,y)", arrayOf("x + y")))
18-
.plugin(Function("g(x,y,z)", arrayOf("f(x,y) + z")))
19-
assertEquals(6, calc.eval("g(1,2,3)").value)
16+
val value = Calculator()
17+
.plugin(Function("f(x)", arrayOf("x + 1")))
18+
.plugin(Function("g(x,y)", arrayOf("f(x) * y")))
19+
.eval("g(3,4)")
20+
.value
21+
assertEquals(16, value)
2022
}
2123
}

0 commit comments

Comments
 (0)