Print debugging statement: Difference between revisions
m
→{{header|Wren}}: Minor tidy
(Added FreeBasic) |
m (→{{header|Wren}}: Minor tidy) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 377:
"q" at line 35 type '*main.point'
value: &main.point{x:2, y:3}
</pre>
=={{Header|Insitux}}==
Here's one method of debugging programs I like to demonstrate: mocking every built-in operation with a function that executes the operation and afterwards outputs its parameters and result.
<syntaxhighlight lang="insitux">
(for s (-> (symbols)
(filter about)
(remove ["print" "mock" "unmocked" "unmock" "do" "reset"]))
(mock s (fn (let result ((unmocked ...) (unmocked s) args))
(print "(" s " " ((unmocked join) " " args) ") => " result)
result)))
(function inside-2d? X Y areaX areaY areaW areaH
(and (<= areaX X (+ areaX areaW))
(<= areaY Y (+ areaY areaH))))
(inside-2d? 50 50 0 0 100 100)
</syntaxhighlight>
{{out}}
<pre>
(fast+ 0 100) => 100
(<= 0 50 100) => true
(fast+ 0 100) => 100
(<= 0 50 100) => true
true
</pre>
For obtaining line and column number, the special value <code>err-ctx</code> evaluates as its own source position.
<syntaxhighlight lang="insitux">
err-ctx
</syntaxhighlight>
{{out}}
<pre>
{:line 1, :col 1}
</pre>
Line 1,131 ⟶ 1,172:
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.
<syntaxhighlight lang="
class Point {
Line 1,195 ⟶ 1,236:
{{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="
import "./debug" for Debug
|