Stream: beginners

Topic: debug on condition


view this post on Zulip Oskar Hahn (Dec 08 2023 at 21:32):

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?

view this post on Zulip Brendan Hansknecht (Dec 08 2023 at 22:07):

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

view this post on Zulip Kilian Vounckx (Dec 09 2023 at 12:46):

I needed this once and used the following:

{} =
    if condition then
        dbg foo
        {}
    else
        {}

Last updated: Jul 05 2025 at 12:14 UTC