I was thinking of a case for dbg that might be interesting. Or it might be clumsy, who knows.
What if it was allowed to have dbg directly after the \ for a function declaration.
myTest = \dbg argOne argTwo ->
argOne + argTwo
This could print out:
dbg: myTest
argOne : 5
argTwo : 10
15
If you were extra fancy, any calls to dbg within that function would be captured in that same block.
myTest = \dbg argOne argTwo ->
otherValue = 3000
dbg otherValue
argOne + argTwo + otherValue
dbg
argOne : 5
argTwo : 10
otherValue : 3000
15
Maybe that's too far.
Why I think this is kinda interesting is that it mirrors how you write a test in that you see the inputs and outputs to a pure function. And trying to get the inputs and outputs for a specific function is a surprising amount of work to do manually.
I like some form of this idea a lot.
Yeah, me too, I'm not sure about this exact syntax but it seems really nice
I want to say do it as
myTest = dbg \argOne, argTwo ->
...
but I'm not sure if that is reasonable. Kinda changes the semantics. That said, debug can't print out lambdas to my knowledge, so I would think it would be safe to do.
I like that syntax idea! :point_up:
we've talked previously about wanting to expand dbg to work as an expression, e.g. foo = dbg (x + 1)
so this could be an extension of that idea: when you do dbg on an expression that's a function, this is the behavior you get
which honestly seems like much more useful behavior than having dbg print <function> every time, which doesn't tell you anything at runtime that you didn't already know at compile time :big_smile:
I have no idea how it is implemented but on Elixir we have contextual aware dbg's - for instance if you put it in a pipeline it will print the output of each step alongside its source code.
I can imagine something like that when used inside a block, printing out each previous statement value that is defined in the same block. So with that in mind this would work:
myTest = \argOne, argTwo ->
otherValue = 3000
argOne + argTwo + otherValue
dbg
myTest = \argOne :: 5, argTwo :: 10 ->
otherValue = 3000 :: 3000
argOne + argTwo + otherValue :: 3015
dbg would read out as "print my context inside this block up until this point"
That's really cool
whoa, cool idea!
I like these explorations of future uses for dbg :rock_on:
the original motivation was just to facilitate basic printline debugging, but I love the idea of taking it further!
Last updated: Jun 16 2026 at 16:19 UTC