Print debugging statement: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(→{{header|Wren}}: Added a second version using Wren-debug.) |
||
Line 1,167: | Line 1,167: | ||
"l" at line 34 type 'Num String Num' |
"l" at line 34 type 'Num String Num' |
||
value: 1 two 3 |
value: 1 two 3 |
||
</pre> |
|||
<br> |
|||
{{libheader|Wren-debug}} |
|||
We can also rewrite this code using the above module which, whilst still quite basic, provides a more structured approach to debugging than the first version. |
|||
<syntaxhighlight lang="ecmascript">import "./fmt" for Fmt |
|||
import "./debug" for Debug |
|||
class Point { |
|||
construct new(x, y) { |
|||
_x = x |
|||
_y = y |
|||
} |
|||
x { _x } |
|||
y { _y } |
|||
toString { "(%(_x), %(_y))" } |
|||
} |
|||
var add = Fn.new { |x, y| |
|||
var result = x + y |
|||
Debug.print("x|y|result|result+1", 16, x, y, result, result + 1) |
|||
return result |
|||
} |
|||
add.call(2, 7) |
|||
var b = true |
|||
var s = "Hello" |
|||
var p = Point.new(2, 3) |
|||
var l = [1, "two", 3] |
|||
Debug.nl |
|||
Debug.print("b|s|p|l", 25, b, s, p, l)</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
EXPR on line 16 of type Int : x = 2 |
|||
EXPR on line 16 of type Int : y = 7 |
|||
EXPR on line 16 of type Int : result = 9 |
|||
EXPR on line 16 of type Int : result+1 = 10 |
|||
NL |
|||
EXPR on line 25 of type Bool : b = true |
|||
EXPR on line 25 of type String : s = Hello |
|||
EXPR on line 25 of type Point : p = (2, 3) |
|||
EXPR on line 25 of type List : l = [1, two, 3] |
|||
</pre> |
</pre> |
||