Print debugging statement: Difference between revisions

Added Wren
No edit summary
(Added Wren)
Line 883:
with   ''one''   argument (as is here),   the
<br>range of random numbers generated are integers from zero to the value of the argument (inclusive).
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
What was said in the preamble to the Go entry applies equally to Wren except that there is no way at present to detect what line number is currently being executed except by aborting the fiber and terminating the script.
 
What is generally done in practice is to hard-code some location indicator (such as the line number itself) at which a variable's value is being obtained. The Go example code then looks like this when translated to Wren.
<lang ecmascript>import "/fmt" for Fmt
 
class Point {
construct new(x, y) {
_x = x
_y = y
}
x { _x }
y { _y }
toString { "(%(_x), %(_y))" }
}
 
var debug = Fn.new { |s, x, lineNo|
Fmt.print("$q at line $d type '$k'\nvalue: $s\n", s, lineNo, x, x)
}
 
var add = Fn.new { |x, y|
var result = x + y
debug.call("x", x, 19)
debug.call("y", y, 20)
debug.call("result", result, 21)
debug.call("result+1", result+1, 22)
return result
}
 
add.call(2, 7)
var b = true
debug.call("b", b, 28)
var s = "Hello"
debug.call("s", s, 30)
var p = Point.new(2, 3)
debug.call("p", p, 32)
var l = [1, "two", 3]
debug.call("l", l, 34)</lang>
 
{{out}}
<pre>
"x" at line 19 type 'Num'
value: 2
 
"y" at line 20 type 'Num'
value: 7
 
"result" at line 21 type 'Num'
value: 9
 
"result+1" at line 22 type 'Num'
value: 10
 
"b" at line 28 type 'Bool'
value: true
 
"s" at line 30 type 'String'
value: Hello
 
"p" at line 32 type 'Point'
value: (2, 3)
 
"l" at line 34 type 'Num String Num'
value: 1 two 3
</pre>
 
=={{header|zkl}}==
9,487

edits