# Python and the ErlangVM

**URL:** <https://forum.elixirforum.com/t/python-and-the-erlangvm/8005>\
**Category:** General Prog (Archived)\
**Created:** [August 21, 2017, 4:55am UTC](https://forum.elixirforum.com/t/python-and-the-erlangvm/8005 "2017-08-21T04:55:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShalokShalom](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shalokshalom/32/15829_2.png) [@ShalokShalom](https://forum.elixirforum.com/u/ShalokShalom)\
**Post date:** [August 21, 2017, 4:55am UTC](https://forum.elixirforum.com/t/python-and-the-erlangvm/8005/1 "2017-08-21T04:55:31Z")

</div>

Can anybody explain me, what is this exactly and how to use it in and with Elixir?  
[http://pyrlang.readthedocs.io/en/latest/](http://pyrlang.readthedocs.io/en/latest/)

---

<div class="post-metadata">

**Author:** ![PatNowak](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/patnowak/32/31275_2.png) [@PatNowak](https://forum.elixirforum.com/u/PatNowak)\
**Post date:** [August 21, 2017, 5:33am UTC](https://forum.elixirforum.com/t/python-and-the-erlangvm/8005/2 "2017-08-21T05:33:50Z")

</div>

As I checked it’s Python’s implementation of Erlang protocol, which enables you connect with Erlang’s Node and eg. communicate with GenServer.

If it works with Erlang, it surely does with Elixir as well.

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/32/27235_2.png) [@NobbZ](https://forum.elixirforum.com/u/NobbZ)\
**Post date:** [August 21, 2017, 5:38am UTC](https://forum.elixirforum.com/t/python-and-the-erlangvm/8005/3 "2017-08-21T05:38:16Z")

</div>

I skimmed the docs and there seem to be many example using python and erlang. Those erlang snippets can be translated directly into elixir using the usual transformation rules.

Prefix modules with colon  
Qualify using dot instead of colon  
Use send instead of!  
Prefix modules with colon  
Don’t use upper case for variables.

If you happen to find an example that you do not understand or can’t translate feel free to ask a more specific question.

---

<div class="post-metadata">

**Author:** ![ShalokShalom](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shalokshalom/32/15829_2.png) [@ShalokShalom](https://forum.elixirforum.com/u/ShalokShalom)\
**Post date:** [August 21, 2017, 5:43am UTC](https://forum.elixirforum.com/t/python-and-the-erlangvm/8005/4 "2017-08-21T05:43:13Z")

</div>

Somebody in IRC tells me, that [Cloudi](http://cloudi.org) is suitable in order to handle throughput inbetween Python and Erlang, because Pyrlang is a single socket connection for distributed Erlang node communication:

This project allows us to have multiple socket connections to python processes (and separate threads if you choose), Some comparison to cnodes is at [CloudI: A Cloud at the lowest level - Frequently Asked Questions](http://cloudi.org/faq.html#4_Erlang)

---

<div class="post-metadata">

**Author:** ![ShalokShalom](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shalokshalom/32/15829_2.png) [@ShalokShalom](https://forum.elixirforum.com/u/ShalokShalom)\
**Post date:** [August 21, 2017, 7:13am UTC](https://forum.elixirforum.com/t/python-and-the-erlangvm/8005/5 "2017-08-21T07:13:48Z")

</div>

And i found a language which i heavly inspired by Pythons Zen, while targeting the ErlangVM:

> **[Efene Programming Language — Efene Programming Language 1.0 documentation](http://efene.org/)**

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/32/2677_2.png) [@OvermindDL1](https://forum.elixirforum.com/u/OvermindDL1)\
**Post date:** [August 21, 2017, 3:34pm UTC](https://forum.elixirforum.com/t/python-and-the-erlangvm/8005/6 "2017-08-21T15:34:27Z")

</div>

> [@ShalokShalom](#):
>
> And i found a language which i heavly inspired by Pythons Zen, while targeting the ErlangVM:  
> [http://efene.org/](http://efene.org/)

Ahh I haven’t heard of that one in a long time. Wonder if it’s community lives. 🙂

EDIT:

Heh, this is an interesting idea:

> Passing functions around is so common in efene that we provide a nicer syntax for it which also enables some really lightweight dsl construction:
> 
> ```efene
> #_ "lists.map:2 takes a function as first argument"
> lists.map(List) <<- case X:
> X + 1
> end
> 
> #_ "mymap takes a function as last argument"
> mymap(List) <- case X:
> X + 1
> end
> 
> ```

I could see similar in Elixir for pipes, hmm, a simple base case:

```elixir
value
|> pipe_into_first_arg(1, 2, 3)
|>> pipe_into_last_arg(1, 2, 3)
||> pipe_into_last_arg(1, 2, 3) # Different syntaxes, hmm...

```

_/me really hates that pipes only pipe into the first arg in elixir, keep having to use my `flip` macro a lot. \>.\<_

---

<div class="post-metadata">

**Author:** ![rvirding](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/rvirding/32/1409_2.png) [@rvirding](https://forum.elixirforum.com/u/rvirding)\
**Post date:** [August 21, 2017, 11:36pm UTC](https://forum.elixirforum.com/t/python-and-the-erlangvm/8005/7 "2017-08-21T23:36:38Z")

</div>

> [@](#):
>
> _/me really hates that pipes only pipe into the first arg in elixir, keep having to use my `flip` macro a lot. \>.\<_

Fred Hébert did an interesting version of something pipe-like where you could indicate where you want the value to go with the `_` variable. IIRC he wasn’t impressed with the pipe idea as such, but I could be wrong here.

---

<div class="post-metadata">

**Author:** ![kylethebaker](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kylethebaker/32/6101_2.png) [@kylethebaker](https://forum.elixirforum.com/u/kylethebaker)\
**Post date:** [August 22, 2017, 4:03am UTC](https://forum.elixirforum.com/t/python-and-the-erlangvm/8005/8 "2017-08-22T04:03:32Z")

</div>

I remember coming across this (an?) erlang mailing list thread by him when searching to see if a pipe operator equivalent exists for erlang.

This is the original thread I read from ~2 years ago: [[erlang-questions] Pipe Operator in Erlang?](http://erlang.org/pipermail/erlang-questions/2015-July/085109.html)

And it looks like he’s created a library for it now: [GitHub - fenollp/fancyflow: Experimental library to bring pipe and maybe operator equivalents in Erlang · GitHub](https://github.com/ferd/fancyflow)

---

<div class="post-metadata">

**Author:** ![kylethebaker](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kylethebaker/32/6101_2.png) [@kylethebaker](https://forum.elixirforum.com/u/kylethebaker)\
**Post date:** [August 22, 2017, 4:35am UTC](https://forum.elixirforum.com/t/python-and-the-erlangvm/8005/9 "2017-08-22T04:35:37Z")

</div>

Do you mind sharing your flip macro works? Or at least what the call looks like?

I think it would be possible to create an `into` macro that converts:

```
value
|> regular_first_arg(1)
|> into irregular_second_arg(1, _, 3)
|> into irregular_third_arg(1, 2, _)

```

into:

```
value
|> regular_into_first(1)
|> (&(irregular_second_arg(1, &1, 3))).()
|> (&(irregular_third_arg(1, 2, &1))).()

```

---

<div class="post-metadata">

**Author:** ![cjen07](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cjen07/32/4410_2.png) [@cjen07](https://forum.elixirforum.com/u/cjen07)\
**Post date:** [August 22, 2017, 5:16am UTC](https://forum.elixirforum.com/t/python-and-the-erlangvm/8005/10 "2017-08-22T05:16:33Z")

</div>

hi, what do you think of this  
[https://github.com/cjen07/param\_pipe](https://github.com/cjen07/param_pipe)

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/32/2677_2.png) [@OvermindDL1](https://forum.elixirforum.com/u/OvermindDL1)\
**Post date:** [August 22, 2017, 2:58pm UTC](https://forum.elixirforum.com/t/python-and-the-erlangvm/8005/11 "2017-08-22T14:58:45Z")

</div>

> [@rvirding](#):
>
> Fred Hébert did an interesting version of something pipe-like where you could indicate where you want the value to go with the \_ variable. IIRC he wasn’t impressed with the pipe idea as such, but I could be wrong here.

There are libraries that add that feature to Elixir in a few forms:

```elixir
a |> blah(1, _, 3) # In the second arg, I like this form

a |2> blah(1, 3) # In the second arg, not a fan of this form, more 'hiding' in my eyes, but it works well

```

> [@kylethebaker](#):
>
> I think it would be possible to create an into macro that converts:

That’s basically what my helpers do, trimmed to a couple things:

```elixir
defmodule PipeHelpers do
  defmacro to_last(value, {fun, meta, args}) do
    x = {:x, [], __MODULE__ }
    call = {:fn, [], [{:->, [], [[x], {fun, meta, args++[x]}]}]}
    {{:., [], [call]}, [], [value]}
  end

  defmacro to(value, {fun, meta, args}) do
    x = {:x, [], __MODULE__ }
    args = Macro.prewalk(args, fn
      {:_, _, _} -> x
      ast -> ast
    end)
    call = {:fn, [], [{:->, [], [[x], {fun, meta, args}]}]}
    {{:., [], [call]}, [], [value]}
  end

  defmacro to(value, i, {fun, meta, args}) do
    i = ast_to_int(Macro.expand_all(i, __CALLER__ ))
    x = {:x, [], __MODULE__ }
    call = {:fn, [], [{:->, [], [[x], {fun, meta, List.insert_at(args, i, x)}]}]}
    {{:., [], [call]}, [], [value]}
  end

  defp ast_to_int(i) when is_integer(i), do: i
  defp ast_to_int({: __block__ , _, [i]}) when is_integer(i), do: i
  defp ast_to_int(ni), do: throw {:ARG_MUST_BE_STATIC_INTEGER, ni}
end

```

Can use it like:

```elixir
blah
|> to_last(something(1, 2)) # Called like `something(1, 2, blah)`

blah
|> to(something(1, _, 2)) # Called like `something(1, blah, 2)

blah
|> to(1, something(1, 2)) # Called like `something(1, blah, 2)

```

I’ve needed the last one before when I did not know the position at ‘programmer-time’ but it is known at compile-time (another macro).

> [@cjen07](#):
>
> hi, what do you think of this

Hah, yeah that’s the one I mentioned before. 🙂

---

<div class="post-metadata">

**Author:** ![ShalokShalom](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shalokshalom/32/15829_2.png) [@ShalokShalom](https://forum.elixirforum.com/u/ShalokShalom)\
**Post date:** [August 23, 2017, 8:15am UTC](https://forum.elixirforum.com/t/python-and-the-erlangvm/8005/12 "2017-08-23T08:15:04Z")

</div>

> [@OvermindDL1](#):
>
> Hah, yeah that’s the one I mentioned before.

The Elixir world is small 😉
