The introduction of Mix.install in Elixir 1.12 was huge. Prior to that single file Elixir scripts could only use the standard library, which is decently sized, counting Erlang but notably misses a good HTTP client and JSON encoding/decoding. Despite using Elixir at my day-job and loving the language in a production environment, I had written off Elixir for scripting and throwaway work until then.
But now, I love it! Mix.install([:req]) at the top and you've got an easy to use, great basis for scripts.
Toss in Livebook and you're well on your way to a wonderful exploratory environment. I've moved off having an open iex window to having a scratch Livebook open, and it's great for little explorations. I've been using it whenever I need to work with my company's API, and over time the little helper modules and functions have been evolving. I almost feel like pretty soon it might as well package it up and release them as a full-fledged Elixir library for use with the API.
That's odd. I downgraded with asdf to 1.12.2 tried the same thing and it worked on my M1. You could try upgrading either Erlang/Elixir. Failing that, there's a lot of helpful people on elixirforum.com (which now features live chat), so it might be best to ask there.
The image classification app[0] written by Chris (creator of Phoenix) is IMO nicer example of single file Elixir/Phoenix app. I had some inspirational moments. Yes, I know it was probably linked on HN before.
I've only just dipped my toes into Elixir and Phoenix but so far really loving it. I feel like I've noticed it popping up on here way more often lately or is that just the ol' frequency bias kicking in?
Perhaps a bit of both? There's been a bump in Elixir posts in the last year or two, which is awesome given that the hype cycle has died down now that the language has been stable for a few years.
I just tried to learn some Elixir, in the latest ubuntu version. and
Mix.install([
{:req, "~> 0.3"}
])
could not compile dependency :mint, "mix compile" failed.
Also mix deps.get say that all dependencies are to date but then mix run gives again that could not compile dependency :mint, "mix compile" failed.
Or you can specify a git commit, or a path if you want to alter it locally.
> No way to keep track of what to change when mix create outputs something different next year.
`mix.lock` keeps track of your resolved dependencies and should be checked in along with your code. Mix/Hex can also be provided the exact `==` versions rather than the `~>` or other Version specifiers
What did you feel you needed to change on your project because the default template had changed? If the code works, then it keeps working.
I've run into this with the Phoenix generators a bit because you need to make changes to your project if you want to update to newer versions of the Phoenix libraries, but they produce documentation about what you need to change.
See, I feel it's a way to have some 'frameworky' elements in my projects that are wonderfully standardized. the changes that do occur usually are worth it.
If anything I sometimes find myself annoyed that Ecto is not there by default, because it's part of almost all my projects, and often even a one-file script might benefit from bits of it.
But now, I love it! Mix.install([:req]) at the top and you've got an easy to use, great basis for scripts.
Toss in Livebook and you're well on your way to a wonderful exploratory environment. I've moved off having an open iex window to having a scratch Livebook open, and it's great for little explorations. I've been using it whenever I need to work with my company's API, and over time the little helper modules and functions have been evolving. I almost feel like pretty soon it might as well package it up and release them as a full-fledged Elixir library for use with the API.
Interactive Elixir (1.12.2) - press Ctrl+C to exit (type h() ENTER for help)
Mix.install([:req]) gives could not compile dependency :mint, "mix compile" failed.
[0] https://github.com/chrismccord/single_file_phx_bumblebee_ml
Embedded with Nerves, the various AI/ML libraries and tooling, LiveBook getting better every day, LiveView innovating and improving DevEx, etc..
Then there's fly.io pushing out content given their target market is developers and they have a big focus on deploying Elixir applications.
aka Baader-Meinhof phenomenon
(since I learned about it, it keeps popping up everywhere)
Single-file scripts that download their dependencies - https://news.ycombinator.com/item?id=34388826
Disclosure: the story is a link to my site.
I have plenty of single-file Elixir examples, many with tests included, in this elixir-snippets repo:
https://github.com/pmarreck/elixir-snippets/blob/master/prin...
Mix.install([ {:req, "~> 0.3"} ])
could not compile dependency :mint, "mix compile" failed. Also mix deps.get say that all dependencies are to date but then mix run gives again that could not compile dependency :mint, "mix compile" failed.
So no good way to learn elixir.
https://github.com/wojtekmach/mix_install_examples/blob/main...
https://github.com/elixir-sqlite/ecto_sqlite3
it's like using Maven or npm all over again. but even worse because it generates a lot of code.
it creates disposable projects by design. No way to keep track of what to change when mix create outputs something different next year.
and now things like https://github.com/wojtekmach/mix_install_examples/blob/main... where is ecto even installed? download from where? so annoying this trend.
For Mix.install you can optionally specify the cache directory. For regular projects they are in the deps folder.
> The location of the cache directory can be controlled using the MIX_INSTALL_DIR environment variable.
https://hexdocs.pm/mix/1.14/Mix.html#install/2
> download from where?
https://hex.pm/packages/ecto
Or you can specify a git commit, or a path if you want to alter it locally.
> No way to keep track of what to change when mix create outputs something different next year.
`mix.lock` keeps track of your resolved dependencies and should be checked in along with your code. Mix/Hex can also be provided the exact `==` versions rather than the `~>` or other Version specifiers
https://hexdocs.pm/elixir/1.14/Version.html
will you have one dep dir on each place you run the script at?
That's how any modern package manager works (I'm thinking cargo as well). I'm not sure why not doing that would be preferable.
most languages dont havea built in package manager.
I've run into this with the Phoenix generators a bit because you need to make changes to your project if you want to update to newer versions of the Phoenix libraries, but they produce documentation about what you need to change.
If anything I sometimes find myself annoyed that Ecto is not there by default, because it's part of almost all my projects, and often even a one-file script might benefit from bits of it.