Stream: beginners

Topic: dbg behaviour


view this post on Zulip Andres Villegas (Dec 10 2022 at 18:01):

Hi! I've been using roc for advent of code for a couple days now, I am very impressed with the language and its features, however I haven't been able to use dbg correctly, sometimes it either panics the compiler or prints stuff that is not correct. For example, this code from the tutorial panics

app "hello"
    packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.1.1/zAoiC9xtQPHywYk350_b7ust04BmWLW00sjb9ZPtSQk.tar.br"}
    imports [pf.Stdout]
    provides [main] to pf

total = addAndStringify {birds: 5, iguanas: 7}

main =
    Stdout.line "There are \(total) animals."

addAndStringify = \counts ->
    dbg counts
    num1 = counts.birds
    num2 = counts.iguanas

    sum = num1 + num2
    if sum == 0     then ""
    else if sum < 0 then "negative"
    else Num.toStr sum

It seems that I might not understand how dbg fully works, my current assumption is that dbg somehow "consumes" the value and then can not be used after. Any tips on how to use dbg effectivelly?

view this post on Zulip Folkert de Vries (Dec 10 2022 at 18:07):

we did just merge some improvements to dbg. How old is your roc compiler?

view this post on Zulip Anton (Dec 10 2022 at 18:10):

How old is your roc compiler?

@Andres Villegas you can check this with roc version

view this post on Zulip Andres Villegas (Dec 10 2022 at 18:53):

it is not that old: roc nightly pre-release, built from commit 234f9f5 on Fri Dec 9 12:57:48 UTC 2022

view this post on Zulip Andres Villegas (Dec 10 2022 at 18:56):

I am on apple Sillicon MacOS 13

view this post on Zulip Anton (Dec 11 2022 at 09:28):

I can check tomorrow if this reproduces on the latest main

view this post on Zulip Anton (Dec 12 2022 at 19:01):

I should be able to do this tomorrow @Andres Villegas, I spent all day trying to fix an issue with my graphics drivers and re-installing my OS.

view this post on Zulip Anton (Dec 13 2022 at 12:42):

This also reproduces on Ubuntu 20.04 with today's nightly, I'll make an issue for it.

view this post on Zulip Anton (Dec 13 2022 at 16:18):

#4752

view this post on Zulip Andres Villegas (Dec 15 2022 at 06:56):

Thanks Anton, I don't use Zulip that much, sorry for the delay answering. I really apreciate your help.


Last updated: Jul 06 2025 at 12:14 UTC