Skip to content

Instantly share code, notes, and snippets.

@djthread
Created December 16, 2020 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djthread/fc396d7ae6029ddcd20372b13abf877e to your computer and use it in GitHub Desktop.
Save djthread/fc396d7ae6029ddcd20372b13abf877e to your computer and use it in GitHub Desktop.
defmodule Foo do
def bar do
:bar
end
end
defmodule Weird do
@moduledoc """
Illustrates a weird behavior I noticed which doesn't seem to make sense.
Set `MIX_ENV` to `prod` and `mix release`. Then, try these:
$ _build/prod/rel/weird/bin/weird eval "Weird.a()"
Function is not exported! Why? :complete amazement:
$ _build/prod/rel/weird/bin/weird eval "Weird.b()"
Function is not exported! Why? :complete amazement:
$ _build/prod/rel/weird/bin/weird eval "Weird.c()"
Function is exported.
"""
# nope
def a do
if function_exported?(Foo, :bar, 0),
do: IO.puts("Function is exported."),
else: IO.puts("Function is not exported! Why? :complete amazement:")
end
# thought maybe loading the app or this might help - no dice
def b do
Application.ensure_all_started(:weird)
a()
end
# but after simply checking the functions on the module like this,
# `function_exported?/3` returns true! By looking, I've changed it;
# Heisenberg principle at work here!
def c do
Foo.__info__(:functions)
a()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment