s7r

s7r

What does the console output represent, after defining an anonymous function?

I am trying to understand the output that is returned by the console when I define an anonymous function. I haven’t been able to find any answer in this forum yet.

Example:
iex(33)> fn x, y -> x + y end
#Function<13.126501267/2 in :erl_eval.expr/5>

  • What is the meaning of the double 13.126501267 ?

Most Liked

easco

easco

If you look in the Elixir code, in the “inspect” module, you can see that the output is derived from calling Function.info. Calling Function.info on an anonymous function on my machine gives me:

iex(5)> some_function = fn x -> x * x end
#Function<7.126501267/1 in :erl_eval.expr/5>
iex(6)> Function.info(some_function)
[
  pid: #PID<0.109.0>,
  module: :erl_eval,
  new_index: 7,
  new_uniq: <<241, 72, 50, 109, 70, 84, 198, 45, 20, 94, 42, 25, 184, 243, 5,
    100>>,
  index: 7,
  uniq: 126501267,
  name: :"-expr/5-fun-4-",
  arity: 1,
  env: [
    {[], :none, :none,
     [
       {:clause, 5, [{:var, 5, :_x@1}], [],
        [{:op, 5, :*, {:var, 5, :_x@1}, {:var, 5, :_x@1}}]}
     ]}
  ],
  type: :local
]

So you can see that the inspect value for the function #Function<7.126501267/1 in :erl_eval.expr/5> consists of the function’s index, uniq and arity pieces.

According to the documentation on Function.info:

:index - (integer) an index into the module function table.

:uniq - (integer) a unique value for this function. This integer is
    calculated from the compiled code for the entire module.

:arity - (integer) the number of arguments the function is to be called
    with.

Now… having figured all that out, it’s still the case that there’s not much the average user can do with that information (well… the arity is useful metadata) - most folks can treat it as a blob of stuff that uniquely identifies the function.

NobbZ

NobbZ

It’s not double. The dot is just a separator. Similar to as in a PID individual segments have their own meaning, but which is not documented nor necessary to know.

NobbZ

NobbZ

What do you mean by “double”? Anyway, there is no meaning in that number. It is opaque., though the /2 indicates arity of the anonymous function.

Where Next?

Popular in Chat/Questions Top

Iex.new
Hello!, I just started this week to discover Elixir. I’m a PHP-Programmer and did some sutff in Go too. The more I read about Elixir t...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
OmanF
In the attached screenshot (taken from an exercise in “Programming Elixir”) can be shown that BugReport is defined as a struct that, itse...
New
shansiddiqui94
Hello all, I recently did my first app in Phoenix and Liveview, many thanks to all the users who assisted me. I found that the tutorial ...
New
Yoga
Or at least, in the works? All I can find are bits and pieces but not a single project from start to finish. Including things like i18n,...
New
maqbool
what books/Resources do you recommend to learn about distributed system(theory)?
New
Santheepkumar
Hi all, I am a Fullstack JS developer for last 2 years. I need a good guide to learn elixer. Any suggestions please
New
AstonJ
It’s been a while since we asked this - I’m sure others (especially newcomers to the language) will be interested to hear how you’ve all ...
New
Fl4m3Ph03n1x
Background After following the communitiy suggestion, I bought the Elixir in Action 2nd Edition book and I am about to finish it now. I ...
New
shansiddiqui94
Greetings Elixir Developers, My name is Daniel, and I am taking my first step to learn all about the Elixir language. Currently I have a...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement