cevado
So I was experimenting with records in elixir and I found it very odd the different behaviour between using records in erlang.
defmodule R do
require Record
Record.defrecord :some, [:a, :b, :c]
end
R.some({:some, 1}, :a)
This would return 1 instead of returning a error of bad record.
while in erlang:
1> rd(some, {a, b, c}).
some
2> B = {some, 1}.
{some,1}
3> B#some.a.
** exception error: {badrecord,{some,1}}
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
rkallos
Unlike in your Elixir example, in your Erlang example, you aren’t actually creating a
#somerecord.This should work instead:
The reason the Elixir example works is definitely interesting. It winds up calling
:erlang.element(2, {:some, 1}), which only works for the:afield. If you try to get:bor:c, it should raise an exception about the index being out of range.I suspect the core misunderstanding might be that
{:some, 1}is not a valid ‘some’ record. The tuple representation of#some{a=1}is{some, 1, undefined, undefined}.cevado
both examples do the same. the
<record_name>/2macro doesn’t create a record, it fetches the field of a record.<record_name>/0and<record_name>/1macros are the ones that create records.from elixir docs:
cevado
this is exactly what i’m reporting… the elixir version doesn’t identify it as a bad record at all.
rkallos
The intent of the examples is the same, but
<record_name>/2uses:erlang.element/2to fetch a field. The Elixir example works on the{:some, 1}input, while the Erlang one doesn’t, because it first checks that the input is a ‘tagged tuple’ with the appropriate arity (in this case; 4).Right!
I guess we could conclude that the reason why the semantics are different in Elixir is because the private function
Record.get/4uses the:erlang.element/2BIF. This avoids checking that the input is a tuple of the correct arity, and that the ‘tag’ element of the tuple matches the record tag. The result of this is that<record_name>/2will work for tuples that aren’t necessarily records.