We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 399a058 commit ede7aa8Copy full SHA for ede7aa8
tests/pos/inline-logging.scala
@@ -0,0 +1,30 @@
1
+object Config {
2
+ inline val logging = true
3
+}
4
+
5
+object Logger {
6
7
+ private var indent = 0
8
9
+ inline def log[T](msg: => String, indentMargin: Int)(op: => T): T =
10
+ if (Config.logging) {
11
+ val msgVal = msg
12
+ println(s"${" " * indent}start $msgVal")
13
+ indent += indentMargin
14
+ val result = op
15
+ indent -= indentMargin
16
+ println(s"${" " * indent}$msgVal = $result")
17
+ result
18
+ }
19
+ else op
20
21
+import Logger._
22
23
+var indentSetting = 2
24
25
+def factorial(n: BigInt): BigInt = {
26
+ log(s"factorial($n)", indentSetting) {
27
+ if (n == 0) 1
28
+ else n * factorial(n - 1)
29
30
0 commit comments