s7r

s7r

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 ?

Showing Posts 1 to 4

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.

s7r

s7r OP

Sorry, I meant a floating point number when I said “double”. Thanks for the reply!

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.

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.

— All posts loaded —

Where Next? Top

Trending in Chat/Questions Top

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews