Erlang interfacing

From Reia

Jump to: navigation, search

As Reia is built on top of Erlang, it can borrow heavily from Erlang's standard library. Most of Reia's standard library will initially consist of wrappers around the Erlang standard library which will add a more Reia-esque feel to them.

But more than that, Reia is intended to exist with existing Erlang projects. Reia can be used for testing or building functionality on top of existing Erlang applications. One of the anticipated uses is adding web interfaces to Erlang applications.

Calling out to Erlang from Reia

The current Erlang interfacing syntax is not finalized and may be subject to change.

Erlang functions can be presently called using the module::function(arg1, arg2, ..., argN) syntax. Future versions of Reia will use the :: operator as the namespace resolution operator, however unlike some silly languages Reia should be able to use the '::' operator for both purposes.

Example:

>> io::format("Hello, world!~n".to_list())
Hello, world!

Calling out to Reia from Erlang

The specific semantics of Reia function calls are still not well-defined. At present they work identically to Erlang function calls, however arguments and return values need to be transformed.

A Reia/Erlang interfacing module, reia_erl, is provided. The function reia_erl:e2r/1 transforms an Erlang term into a Reia one and can be used for function arguments, while reia_erl:r2e/1 can be used to transform the return value.

In the future an apply-style function will be provided to make calls to Reia from Erlang and automatically transform the arguments and return value.

Potential "import" syntax

The "import" syntax is still undecided, but will likely take the form of a function call.

Possible syntax:

# Example 1
>> import(~io, IO)

# Example 2
>> import io as IO

# Example 3
>> import io => IO

In any of these cases, the import will make the given Erlang module (in these examples, "io") available as a Reia module of the given name (in this case "IO"). The Erlang module will then be callable using the normal Reia function invocation syntax, and thunking between Erlang and Reia data types will happen automatically:

# Example
>> IO.format("Hello, world!~n".to_list())
Hello, world!
Personal tools