Print debugging statement: Difference between revisions
Content added Content deleted
(Added FreeBasic) |
(→Insitux: inclusion) |
||
Line 377: | Line 377: | ||
"q" at line 35 type '*main.point' |
"q" at line 35 type '*main.point' |
||
value: &main.point{x:2, y:3} |
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> |
</pre> |
||