Skip to content

Commit d728f78

Browse files
authored
Merge pull request #56 from javecs/feature/readme-plugin
ユーザー定義関数の使い方について説明を修正しました。
2 parents 99a912e + 5bec1a9 commit d728f78

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,16 @@
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("x = 3")
73+
.eval("y = 4")
74+
.eval("g(x,y)")
75+
.value
76+
println(value)
77+
78+
結果は、 16 です。
7579
```
7680
7781
## 計算可能な数式

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ 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("x = 3")
20+
.eval("y = 4")
21+
.eval("g(x,y)")
22+
.value
23+
assertEquals(16, value)
2024
}
2125
}

0 commit comments

Comments
 (0)