maxguzenski
Hi everyone,
I’m using Elixir 1.18.4 with OTP 27 (I’ve tested this across multiple versions of both Elixir and Erlang), and surprisingly, the expression nil > 25 returns true. Is this correct?
Both ChatGPT and Claude stated that this should not be possible — that a comparison like this should raise an ArgumentError, as nil cannot be compared to numbers using > or <. They even suggested that something might be wrong with my machine.
However, I tested this on https://playground.functional-rewire.com/ as well, and I got the same result: nil > 25 returns true.
So my question is:
Has it always been this way, or is this a recent change/bug?
Thanks in advance!
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
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
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #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
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sodapopcan
Yes, comparison operators can be used across types. As for why
nil > 25returnstrue, see the good ol’ docs. Of note:nilis simply syntactic sugar for the atom:nil(you can prove it withiex> nil == :nil).maxguzenski
I see. I’ve been programming in Elixir for about 10 years, and I had never run into this “behavior” before—perhaps because I always used is_nil/1 or is_number/1 in guards. But today, my tests started failing after I added a guard like when ver > 25.
What surprised me is that two AIs insisted it couldn’t be true. ChatGPT even gave me several links “proving” it would raise an error, but those links pointed to Elixir pages that didn’t actually mention anything related to this specific case.
thanks
sodapopcan
You sound like one of those people who actually know how to use a dynamic programming language properly
Also, we’re in the BEAM world here so I believe you meant “behaviour” 
As grumpy old man jumping on the opportunity to rant this has been fairly common recently, “common” meaning this is the ~7th time in a couple of months I’ve seen a question online where people said they just asked AI, and not just for Elixir questions! I’m sure it’ll all be “fixed” soon enough, but I still enjoy reading docs.
Back on track, another little gotcha is that
trueandfalseare also sugar for:trueand:false, so when you thrownilinto the mix and compare them it’s done so alphabetically. I know a couple of people who got tripped up by this because they assumed that sincetrueis greater thanfalsethatfalsewould be greater thannil, but it’s not. Though again, if you aren’t abusing dynamic languages then you’ll never run into thisk, I’m off to go yell at a cloud.
al2o3cr
The LLMs appear to have transposed behavior over from Ruby, FWIW:
As you’ve noticed, the BEAM instead defines a total order (TLDR “everything compares to everything”).
This is mostly useful for code that handles opaque terms, like ETS’s
ordered_set. The rest of the time you usually want to know (either by guards or by correct code) that you’re comparing terms of the expected type.There’s a great writeup in The BEAM Book, including the rules for all the other kinds of terms.
sodapopcan
Well sure, there are years worth of “information” on the internet from folks claiming “Elixir is just Ruby with some extra
dos”.adamu
dogweather
I no longer trust LLMs with quantitative questions that have objectively true answers. They’re just not so good at that, nor will ever be perfect. They will though, be as good or better than a human, which is a good goal.
What I’m seeing now is AI programmed to come up with a “correct” answer in tightly confined answer spaces, giving confidence scores along the way.
sabiwara
While there is no runtime warning for the reasons explained above, it’s worth noting that the new type system might be able to catch it and warn at compile time when it is sure types are disjoint:
Asd
Hmm, have you tried
nil > 26? It might be that nil equals to something between 26 and 25. We should try binary searchmudasobwa
…and a clunky implementation of
method_missing!