First-class models in Erlang?

Is there support for top-notch templates in Erlang?

f(SomeMagicPattern) -> receive SomeMagicPattern -> ok end. 

If there is no answer (support), do you know any other approach to achieve this? For example, using macros?

+4
source share
2 answers

No, Erlang does not have first-class templates out of the box. This can be implemented in two ways:

  • Macros. Widely used, for example, in testing tools such as EUnit and PropEr. Say EUnit has a macro? AssertMatch, which is actually an example of first-class templates:

    ? assertMatch ({ok, _}, Result)

  • Converts syntax. It is harder to write, but potentially more powerful, because with their help you can access the Erlang Erlang code and completely rewrite it, in any way. There's a good link to a series of parsing tutorials transforming here: There is a nice, complete Erlang parsing tutorial transforms available

+4
source

As Demeshchuk points out, this is not so.

However, there is a suggestion to add something similar to the language:

http://www.erlang.org/eeps/eep-0029.html

Is this a good idea, this is a completely different question ...

+1
source

Source: https://habr.com/ru/post/1436358/


All Articles