简体   繁体   中英

Mixing Elixir and Erlang?

There are some Erlang constructs I would want to use inside Elixir code. One is Erlang list comprehensions.

My general question is whether there is some way to 'drop down' to writing Erlang code while coding in Elixir (sort of the way you see people embed C in Ruby or TCL or whatever). My specific question (related to the general) is whether it is possible for me to somehow get Erlang-style list comprehensions while coding in Elixir.

If this isn't possible with plain Elixir, perhaps it can be done through a macro (possibly difficult?)? I do understand that I can just write an Erlang module and call it from Elixir, but that's not quite what I'm looking for.

There isn't a mechanism today for you to inline Erlang in Elixir. If you think about it, even simple list comprehensions would get tricky rather quickly because a variable in Elixir follows different casing conventions than Erlang. So you would need to convert values and that would probably get so verbose to the point of not being worthy it.

Comprehensions in particular would be hard to be more "erlangy" but maybe some of your other complaints could be addressed. We would need to discuss them in a case-by-case basis though.

I agree some mechanisms in Elixir are slightly more verbose than Erlang (function definitions being my personal pet peeve) and vice-versa. But it is hard to put everything in the same bucket, something has to give at some point. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM