mudasobwa

mudasobwa

Creator of Cure

I’ve been heavily working with macros for more than 10 years already and I always used kinda ad-hoc code to expand/debug/test those when in trouble.

So yeah, it’s better to get a reputation of a slowpoke rather than to spend another 10 years fighting the ghosts.

Welcome ExPanda library that expands macros all the turtles down (short of defmodule and def/defp/defmacro/defmacrop structural forms.)

It’s time to take a look at what use GenServer does actually become in your code:

iex|🌢|1 ▶ "defmodule M, do: use GenServer"
          |> ExPanda.expand_to_string()
          |> elem(1)
          |> IO.puts() 

defmodule M do
  require GenServer
  opts = []
  @behaviour GenServer
  case :erlang.not(Module.has_attribute?(M, :doc)) do
    false ->
      nil

    true ->
      Module.__put_attribute__(
        M,
        :doc,
        {0,
         "Returns a specification to start this module under a supervisor.\n\nSee `Supervisor`.\n"},
        nil,
        []
      )
  end

  def child_spec(init_arg) do
    default = %{id: M, start: {M, :start_link, [init_arg]}}
    Supervisor.child_spec(default, unquote(Macro.escape(opts)))
  end

  defoverridable child_spec: 1
  @before_compile GenServer
  @doc false
  def handle_call(msg, _from, state) do
    proc =
      case Process.info(:erlang.self(), :registered_name) do
        {_, []} -> :erlang.self()
        {_, name} -> name
      end

    case :erlang.phash2(1, 1) do
      0 ->
        :erlang.error(
          RuntimeError.exception(
            <<"attempted to call GenServer ", String.Chars.to_string(inspect(proc))::binary,
              " but no handle_call/3 clause was provided">>
          ),
          :none,
          error_info: %{module: Exception}
        )

      1 ->
        {:stop, {:bad_call, msg}, state}
    end
  end

  @doc false
  def handle_info(msg, state) do
    proc =
      case Process.info(:erlang.self(), :registered_name) do
        {_, []} -> :erlang.self()
        {_, name} -> name
      end

    :logger.error(
      %{label: {GenServer, :no_handle_info}, report: %{module: M, message: msg, name: proc}},
      %{
        domain: [:otp, :elixir],
        error_logger: %{tag: :error_msg},
        report_cb: &:erlang./(GenServer.format_report(), 1)
      }
    )

    {:noreply, state}
  end

  @doc false
  def handle_cast(msg, state) do
    proc =
      case Process.info(:erlang.self(), :registered_name) do
        {_, []} -> :erlang.self()
        {_, name} -> name
      end

    case :erlang.phash2(1, 1) do
      0 ->
        :erlang.error(
          RuntimeError.exception(
            <<"attempted to cast GenServer ", String.Chars.to_string(inspect(proc))::binary,
              " but no handle_cast/2 clause was provided">>
          ),
          :none,
          error_info: %{module: Exception}
        )

      1 ->
        {:stop, {:bad_cast, msg}, state}
    end
  end

  @doc false
  def terminate(_reason, _state) do
    :ok
  end

  @doc false
  def code_change(_old, state, _extra) do
    {:ok, state}
  end

  defoverridable code_change: 3, terminate: 2, handle_info: 2, handle_cast: 2, handle_call: 3
end

https://github.com/am-kantox/ex_panda

Enjoy!

Showing Posts 1 to 5

cmo

cmo

Nice. I’ve been patiently waiting years for someone to integrate this sort of thing into the LSP for me.

nulltree

nulltree

10/10 name.

mudasobwa

mudasobwa OP

Creator of Cure

The version 1.0 is to roll out with a motto “chewing bamboo shoots to the roots.”

mudasobwa

mudasobwa OP

Creator of Cure

I have plans to ping ExpertLSP team members after I have it tested thoroughly with my own Ragex.

dmitrykleymenov

dmitrykleymenov

Wow, thanks for sharing. It could be pretty helpful

— All posts loaded —

Where Next? Top

Trending in Announcing Top

restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 12366 136
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
kip
I’ll shortly be launching Text, a nascent text analysis library. Current functionality In this early version (not ready for prime time) ...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews