shijith.k

shijith.k

Basic < Operator working between integer and list

How does the < work? By accident, in my code, I compared an integer with a list, and it gave me a boolean value as response instead of error.

iex(1)> integer = 1
1
iex(2)> list = [1]
[1]
iex(3) integer < list
true

So how does the operator work here?

Marked As Solved

NobbZ

NobbZ

</2 and friends work by comparing “terms” as explained in the erlang manual:

Also Liked

kelvinst

kelvinst

It is also explained on the Elixir guides: https://elixir-lang.org/getting-started/basic-operators.html

For those who don’t want to open another site:

The reason we can compare different data types is pragmatism. Sorting algorithms don’t need to worry about different data types in order to sort. The overall sorting order is defined below:

number < atom < reference < function < port < pid < tuple < map < list < bitstring
kelvinst

kelvinst

PS.: just expressing my opinion on the matter, I think this is a really nice way to handle comparison between different data types. I mean, a lot better than what JS does, trying to discover what the user means by comparing different types. And that also allows some powerful stuff, like using any type as a key on maps and still be able to do a binary search on it, without any extra function needed :smiley:

Last Post!

kelvinst

kelvinst

PS.: just expressing my opinion on the matter, I think this is a really nice way to handle comparison between different data types. I mean, a lot better than what JS does, trying to discover what the user means by comparing different types. And that also allows some powerful stuff, like using any type as a key on maps and still be able to do a binary search on it, without any extra function needed :smiley:

Where Next?

Popular in Questions Top

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130286 1222
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement