[erlang-questions] core erlang, scope, primop

Richard Carlsson richardc@REDACTED
Tue Oct 14 09:33:12 CEST 2008


denis wrote:
> I've two questions on core erlang:
> 
> Concerning the scope of variables: when using let, the scope of the
> variables is the body of the let. But when a variable is defined by a
> pattern matching or by an alias, what is the scope ? I suppose that
> it's the function, but I've not been able to find references of that
> in the core erlang 1.0.3 specifications.

This is described at the top of page 15, under "Case:". The scope is
the body of the clause, and also the guard (follow the reference to
section 6.6). (Core Erlang isolates all pattern matching to the case
expressions, so things are a lot easier than in the full Erlang.)

> Concerning primop: is there a way to call these functions in erlang ?
> If not, is it possible to know all primops that are used by erlang
> compiler when generating core erlang ?

Not as such. As explained in section 7, the primops are only there to
help on the implementation level, to represent internal operations that
do not generally have a corresponding Erlang function somewhere. They
are thus completely dependent on the compiler and VM implementation.

However, the number of primops used by the OTP compiler is pretty small,
and can be found rather quickly by inspecting some core code generated
from typical Erlang source files and grepping under lib/compiler/src.

> As you may understand, I'm toying with writing a core erlang evaluator.

There should really have been an official interpreter, but I never got
time to finish it. Have fun!

   /Richard



More information about the erlang-questions mailing list