I tried to dgb a value in a recursive function, but only after some depth. For example
myFunc = \value, idx ->
if idx % 10 == 0 then
dbg value
if value == 0 then
idx
else
myFunc (somecalc value) (idx + 1)
Currently, this is not possible, since the if expression can not be parsed.
It is possible to write a helper like this:
dgbCondition = \cond, v ->
if cond then
dbg
v
v
else
v
But it prints the wrong line-number and you have to call it by prefixing it with _ =
.
Would it be possible to add something like dbgCondition?
Interesting. So the core issue here is that roc doesn't allow if idx % 10 == 0 then
as a standalone currently. If is an expression that must always have an else and return a value
I needed this once and used the following:
{} =
if condition then
dbg foo
{}
else
{}
Last updated: Jul 05 2025 at 12:14 UTC