defmodule Foo do
# stolen from:
# https://github.com/elixir-lang/elixir/blob/v1.16.3/lib/elixir/lib/kernel.ex#L3401-L3412
defmacro bar(pattern, expr) do
success =
quote do
unquote(pattern) -> true
end
failure =
quote generated: true do
_ -> false
end
{:case, [], [expr, [do: success ++ failure]]}
end
end
{:module, Foo, <<70, 79, 82, 49, 0, 0, 7, ...>>, {:bar, 2}}
true
error: invalid use of _. _ can only be used inside patterns to ignore values and cannot be used in expressions. Make sure you are inside a pattern or change it accordingly
└─ /Users/bcardarella/Library/Application Support/livebook/autosaved/2024_06_06/22_13_a3vw/reproduce_match.livemd#cell:lb67qauyh2hfo2qh:1