[erlang-questions] The Core Erlang AST via cerl.erl and Sequence returns from functions

Richard Carlsson carlsson.richard@REDACTED
Wed Dec 21 21:45:31 CET 2011

On 2011-12-21 17:36, Eric Merritt wrote:
> Guys,
> I am currently targeting the Erlang VM for a custom language via core
> erlang as defined in cerl.erl on R15B. I have run into an interesting
> issue. In a Let form (cerl:c_let) if I have a sequence of c_vars on
> the Variable arguement and c_apply (on a function that returns a
> c_values) in the Argument argument then the erlang compiler exits with
> an 'error'. However, if I have a c_values directly as the Argument
> argument the compiler will compile the form. Either I am understanding
> something incorrectly or this is a bug in the cerl compiler. I am
> hoping one of the folks that is knowledgeable on the subject can help
> out. In short the following works:
>      cerl:c_let([cerl:c_var(x0), cerl:c_var(x1)],
> cerl:c_values([cerl:c_int(0), cerl:c_int(1)]), cerl:c_atom(foo))
> while this does not:
>      <define a function that returns cerl:c_values([cerl:c_int(0),
> cerl:c_int(1)])>
>      cerl:c_let([cerl:c_var(x0), cerl:c_var(x1)],
> cerl:c_apply(cerl:c_fname(my_fun, 0), []), cerl:c_atom(foo)).

Intuitively (and without consulting the source code or my old papers on 
Core Erlang), I'd say that the latter should work. However, the OTP 
compiler doesn't try to be complete with respect to all possible Core 
Erlang programs - it only bothers to implement what's needed to handle 
code that's first been translated from (full) Erlang. So if you start 
generating arbitrary but legal Core Erlang, you may run into corner 
cases (in this case, it seems that multiple return values aren't handled 
as they ought to be). See if you can find the problem in the compiler - 
as Calvin's dad used to say, "it builds character". :-)


More information about the erlang-questions mailing list