Rich_Morin

Rich_Morin

Is anyone using AI assistance in coding Elixir?

I’m curious whether anyone is using AI (really, LLM) assistance in coding Elixir (especially in Livebooks). If so, which chatbots (etc) seem to be working the best?

First Post!

CharlesIrvine

CharlesIrvine

I use ChatGPT quite a bit by asking - “How do I do this using Elixir?” The answers are usually pretty good. Here’s a question I just asked today along with the response:


My question:

Using Elixir, how do I check to see if two lists have the same members, regardless of the order?

ChatGPT said:

ChatGPT

In Elixir, you can check if two lists contain the same members, regardless of order, by sorting each list and comparing them. This approach works because sorting ensures both lists will have the same order if they contain the same elements.

Here’s a simple example:

def same_members?(list1, list2) do
  Enum.sort(list1) == Enum.sort(list2)
end

Example Usage

same_members?([1, 2, 3], [3, 2, 1]) # returns true
same_members?([1, 2, 3], [3, 2, 2]) # returns false

This approach works well for lists with unique elements. However, if you have large lists and performance is a concern, you might consider using a different approach that doesn’t require sorting, such as converting the lists to maps of element counts and comparing those.

You said:

Are you sure there isn’t a built in function that does this check?

ChatGPT said:

ChatGPT

You’re right; Elixir actually has a built-in function for this exact purpose: Enum.frequencies/1. By using it, you can create a frequency map for each list and then compare those maps directly, which is both efficient and concise.

Here’s how you can do it:

def same_members?(list1, list2) do
  Enum.frequencies(list1) == Enum.frequencies(list2)
end

Example Usage

same_members?([1, 2, 3], [3, 2, 1]) # returns true
same_members?([1, 2, 3], [3, 2, 2]) # returns false

Using Enum.frequencies/1 is beneficial because it directly compares the counts of each unique element in each list, which avoids sorting and is faster for large lists.

Most Liked

ipnon

ipnon

It will direct you to your particular Dunning-Kruger minima as fast as possible and once there assure you that a better solution is inconceivable.

dimitarvp

dimitarvp

I was about to write that I broke my LLM virginity lately. I needed help with an obscure-ish library that assumes 100% proficiency in its domain to be used. Claude taught me how to use it and helped me troubleshoot a problem with the input data.

I still don’t view LLMs as killing programming – they are VERY long way from that – but I can’t deny that with the main search engines being near-useless, the LLMs fill some gaps well.

cmo

cmo

It is a Large Language Model, not a Large Problem Solving Model after all. A lot of people aren’t managing their own expectations very well when it comes to LLMs.

Last Post!

Awlexus

Awlexus

Why I don’t like the Zed AI integration, or AI integration in general

Prompting with reasoning models includes the whole thinking process, which makes for clunky integratation. Other models I tried would wrap the code in {{code}} occationally and I couldn’t really find any models that generate usable code for the things I asked.

Why I don’t like Zed itself

In terms of why I don’t like the editor, the shortcuts are impractical compared to the ones of the text editor and still require you to use the mouse every now and then. Additionally, many shortcuts simply don’t work under linux, which is an absolute dealbreaker.
The configuration being a json file for a graphical text editor is a thing I already heavily disliked for VS code.

Where Next?

Popular in Discussions Top

Crowdhailer
I’ve been hearing much about the new formatter and it’s something I have been keen to try. I find examples buy far the most illuminating...
248 19814 150
New
MarioFlach
Hello, I want to share a project I’ve been working on for a while: https://github.com/almightycouch/gitgud Background Some time ago I ...
New
wmnnd
The Go vs Elixir thread got me thinking: Would it be too hard to implement a simple mechanism for creating Go-style static app binaries f...
New
tmbb
This is a post to discuss the new Phoenix LiveView functionality. From Chris’s talk, it appears that they generate all HTML on the serve...
342 18634 126
New
Fl4m3Ph03n1x
Background This question comes mainly from my ignorance. Today is Black Friday, one of my favorite days of the year to buy books. One boo...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New
paulanthonywilson
I like Umbrella projects and pretty much always use them for personal Elixir stuff, especially Nerves things. But I don’t think this is ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New

We're in Beta

About us Mission Statement