Live data from Hacker News

Embedding Python in Elixir, it's fine

dashbit.co

21–30 of 66 posts

Re: Embedding Python in Elixir, it's fine

#21
post #8
post #7

Elixir has some features I wish Python had: - atoms - everything (or most things) is a macro, even def, etc. - pipes |>, and no, I don't want to write a "pipe" class in Python to use it like pipe(foo, bar, ...). 90% of the |> power comes from its 'flow' programming style. - true immutability - true parallelism and concurrency thanks to the supervision trees - hot code reloading (you recompile the app WHILE it's runni…

Mix is also so much better than anything python has to offer in terms of build/dependency tooling.

uv for Python is a game changer, better than anything else out there and solves a lot of the core problems with pip/venv/poetry/pyenv (the list goes on).

Re: Embedding Python in Elixir, it's fine

#23
post #19

Really glad to see this, Elixir has languished in the AI wars despite being a better fit than JavaScript and Python.

Forgive some ignorance on this; why is Elixir a better fit for AI than Python or JavaScript? I'm not disagreeing, I've just never heard that, I didn't think that Elixir had good linear algebra libraries like NumPy.

It does now with Nx

Re: Embedding Python in Elixir, it's fine

#24
post #21
post #8

Earlier quoted context omitted.

Mix is also so much better than anything python has to offer in terms of build/dependency tooling.

uv for Python is a game changer, better than anything else out there and solves a lot of the core problems with pip/venv/poetry/pyenv (the list goes on).

I feel like you can write some variant of this comment every few years and just add the previous "best" to the front of the stack of things it's better than.

Re: Embedding Python in Elixir, it's fine

#25
post #21

Earlier quoted context omitted.

uv for Python is a game changer, better than anything else out there and solves a lot of the core problems with pip/venv/poetry/pyenv (the list goes on).

I feel like you can write some variant of this comment every few years and just add the previous "best" to the front of the stack of things it's better than.

It’s true - people were saying that Poetry solves these problems for ages. Maybe uv does? I’ll wait and see.

Re: Embedding Python in Elixir, it's fine

#26
Elixir is just Lisp with a facelift[1], and lisps can be built on Python[2]. It stands to reason that an elixir-like can be built on Python too, so you could embed the Python runtime in Elixir but Elixir-likes are used to code for both.

1: https://wiki.alopex.li/ElixirForCynicalCurmudgeons

2: https://hylang.org/

Re: Embedding Python in Elixir, it's fine

#27
post #7

Elixir has some features I wish Python had: - atoms - everything (or most things) is a macro, even def, etc. - pipes |>, and no, I don't want to write a "pipe" class in Python to use it like pipe(foo, bar, ...). 90% of the |> power comes from its 'flow' programming style. - true immutability - true parallelism and concurrency thanks to the supervision trees - hot code reloading (you recompile the app WHILE it's runni…

You can abuse the '>>' notation in python for pipes (or you could use |, I suppose), but you'll have to deal with whitespace shenanigans. I'm also not entirely sure about the order of evaluation. And you'll need to do partial function application by hand if you want that (though it is possible to write a meta function for that).

So one could write

    class Piped:
        def __init__(self, value):
            self.value = value
    
        def __or__(self, func):
            return Piped(func(self.value))
    
        def __repr__(self):
            return f"Piped({self.value!r})"
    
    Piped('test') | str.upper | (lambda x: x.replace('T', 't')) | "prefix_".__add__ # => prefix_tESt
but whether that is a good idea is a whole different matter.

Re: Embedding Python in Elixir, it's fine

#28

Elixir is just Lisp with a facelift[1], and lisps can be built on Python[2]. It stands to reason that an elixir-like can be built on Python too, so you could embed the Python runtime in Elixir but Elixir-likes are used to code for both. 1: https://wiki.alopex.li/ElixirForCynicalCurmudgeons 2: https://hylang.org/

In a way Python is a bad Lisp, still looking forward that catches up in native code compilation and multiline lambdas.

Could be better, but that is what mainstream gets.

Re: Embedding Python in Elixir, it's fine

#29
post #19

Really glad to see this, Elixir has languished in the AI wars despite being a better fit than JavaScript and Python.

Forgive some ignorance on this; why is Elixir a better fit for AI than Python or JavaScript? I'm not disagreeing, I've just never heard that, I didn't think that Elixir had good linear algebra libraries like NumPy.

Sorry, I should have been more explicit: better for on the user facing implementation side (concurrency, streaming data, molding agent state, etc) vs the training side of things. If that makes sense.

Re: Embedding Python in Elixir, it's fine

#30
post #13

For Livebook, this looks really cool. Love that it calls CPython directly via C++ NIFS in Elixir and returns Elixir-native data structures. That's a lot cleaner than interacting with Python in Elixir via Ports, which is essentially executing a `python` command under the hood. For production servers, Pythonx is a bit more risky (and the developers aren't claiming it's the right tool for this use case). Because it's ru…

One possibility for production use (in case there is a big value) is to split the nodes into one "front" node which requires strong uptime, and a "worker" node which is designed to support rare crashes gracefully, in a way that does not impact the front.

This is what we use at https://transport.data.gouv.fr/ (the French National Access Point for transportation data - more background at https://elixir-lang.org/blog/2021/11/10/embracing-open-data-...).

Note that we're not using Pythonx, but running some memory hungry processes which can sometime take the worker node down.

Post reply on HN