romul
Recently I read release notes of Rust 1.32 and was impressed of dbg macro convenience.
Therefore I decided to implement the same concept in Elixir.
Here is the result: GitHub - romul/dbg_inspect: Implementation of dbg! Rust-macro for Elixir · GitHub
Additional features comparing to IO.inspect/1:
- Prints representation of expression passed as the first argument
- Prints filename and line number where Dbg.inspect/2 was called
- Ability to print values of all variables used in the expression passed as the first argument
- Colored output
- Output to :stderr stream
- No affects prod environment
Output example:
IO.inspect/1 output for the same case:
%{0 => "0", 1 => "1", 2 => "4", 3 => "9"}
Trending in Announcing
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi all!
I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas.
You...
New
Hello
Published a new library - ProcessHub!
ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
This showed up on my feed.. anyone heard of it? Just hype?
Ox Alpha is a reasoning model designed for coding, sustained ag...
New
It’s not that it’s vocabulary is too advanced. It’s something worse.
I get lost trying to follow even a paragraph written by Claude. It’...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Fl4m3Ph03n1x
Does it return the value it receives like
IO.inspectper default?wojtekmach
Yes,
dbg!macro looks really interesting!Here’s my take on it: https://github.com/wojtekmach/elixir/commit/27d0019e1d21a3b2f7946a353c2439096df53612.
I think it needs to be in Kernel to be most usable because we need to
require/importit to use it, and it’s gonna be annoying to do it every time.I showed this to a few people and still collecting feedback before proposing this as a feature.
romul
Yes, it does. So you could use it in the middle of pipeline, like this: dbg_inspect/test/dbg_test.exs at master · romul/dbg_inspect · GitHub
romul
Well, don’t you mind to unite our efforts to provide even more useful solution than Rust out of the box? As you can see I’ve already implemented several additional features for this macro. I could transfer them to your branch. So we will have 2 commits in the proposal
wojtekmach
I’m pretty happy with the limited feature set I’ve implemented but additional features you’ve added sound interesting too, I’ll definitely play with them. Feel free to argue for these additions when there’s a proposal or send the proposal yourself
Some feedback:
show_vars: truelooks interesting. I didn’t have a need for it yet, but will definitely keep it in mind.Special casing variables in just the first call seems somewhat arbitrary, it wouldn’t for example show
yinDbg.inspect(x |> max(y))and that could be a bug or a feature, not sure! Perhaps it should show all variables used in an expression? You can get them usingKernel.binding.if the function is defined as
inspect/2, there’s a clash withKernel.inspect/2so you wouldn’t be able to import it out of the box. One of my goals for this macro was to be available right away, but perhaps that’s no such a big deal, similarly how writingrequire IEx; IEx.pry()isn’t? I’ll definitely try this for a few days without this being in Kernel.Dbgis perhaps too similar with OTP’s:dbgmodule? That being said, I’m not super happy withKernel.debugname either but couldn’t come up with neither better module nor function name.romul
Yeah, it was a bug. Fixed already, thank you for pointing it out.
And
Kernel.bindinglooks very promising, I’ll take a look.Yes, I thought about
Dbg.inspect()as an alternative toIO.inspect(), looks similar and almost the same amount of typing. But yeah, looks like Dbg is already used module name. I would be happy withIO.debug(), but it also is not an optionwojtekmach
hm, why not? I believe it wouldn’t clash with anything. (it could clash with Logger.debug/2, but it’s not common to important that). The only downside of making it
IO.inspectIO.debugto me is we’d have to require it.romul
Yes, that’s because
IOmodule doesn’t have macros yet. And even we put one to it, writingrequire IOwould be necessary. So, there would be not much advantage to put it to Elixir itself.A standalone library on contrary has a few advantages, for example you could configure coloring or set default options through configuration.
wojtekmach
In my implementation I allowed to pass inspect options, e.g.:
but if you want to get the same colour scheme every time, well, it gets tiresome. Some things are configured globally in Elixir (e.g. elixir/lib/elixir/lib/calendar.ex at v1.8.0 · elixir-lang/elixir · GitHub) but it’s much less common. So yeah, being able to configure this globally seems more appropriate for a standalone library.
romul
Yep, passing the same configuration as param all the time is too tedious.
There is almost no chance that you would like to use different coloring for the same purpose, but you highly likely could have a preferred color scheme, padding settings and so on.