I know we can bind variable using
@ at the global level
I am trying to bind this example but in elixir how ?
-define(INT, 32/big-signed-integer).
I tried @int 32-big-signed-integer,
but it doesn’t work, anyone can help me please
You can’t do this as an attribute, as the attribute would try to evaluate at compiletime to 32 divided by the value of big-signed-integer. which is probably not defined.
So with a bit of luck you might be able to write a macro that works for you, something like
defmacro i32() do
quote do: 32/big-signed-integer
end
This is good when doing a pattern matching on long bitstring, for example
[ {key, value} || <<key::size, value::size>> <= <<map_buffer>>]
this is kinda a mix between For loop and bitstring patternmatching.
this could be done in erlang, but in elixir I had to implement a very long logic to do so
any idea how ?