简体   繁体   English

混合Elixir和Erlang?

[英]Mixing Elixir and Erlang?

There are some Erlang constructs I would want to use inside Elixir code. 我想在Elixir代码中使用一些Erlang构造。 One is Erlang list comprehensions. 一个是Erlang列表理解。

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). 我的普遍问题是,是否有某种方法可以在使用Elixir进行编码时“下降”到编写Erlang代码(这类似于人们将C嵌入Ruby或TCL或其他方式的方式)。 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. 我的具体问题(与一般问题有关)是,在Elixir中进行编码时,是否有可能以某种方式获得Erlang样式的列表理解。

If this isn't possible with plain Elixir, perhaps it can be done through a macro (possibly difficult?)? 如果使用普通的Elixir是不可能的,也许可以通过宏来完成(可能很难?)? 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. 我确实知道我可以编写一个Erlang模块并从Elixir调用它,但这并不是我想要的。

There isn't a mechanism today for you to inline Erlang in Elixir. 今天没有一种机制让你在Elixir中内联Erlang。 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. 如果你考虑一下,即使简单的列表推导也会变得棘手,因为Elixir中的变量遵循不同的套管约定而不是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. 我同意Elixir中的一些机制比Erlang稍微冗长(函数定义是我个人的烦恼),反之亦然。 But it is hard to put everything in the same bucket, something has to give at some point. 但是很难将所有内容放在一起,这在某些时候必须付出。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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