[erlang-questions] Is Erlang dynamic language?

Jesper Louis Andersen <>
Mon Nov 29 22:23:19 CET 2010


On Mon, Nov 29, 2010 at 9:41 PM, Andrey Paramonov
<> wrote:
>
> Many people associate dynamic languages with metaprogramming, runtime
> method injection, AST transformations and the like. As far as I can
> tell, there is no such things in Erlang. But on the other hand, Erlang
> has runtime code update and you can change runtime behaviour by
> passing functions to the methods. So it seems to be dynamic.

Erlang actually has all of the things you associate with a dynamic
language as Tony Arcieri hinted. As for the dynamically/statically
typing question, one way to see it (which is in the first few chapters
of SICP if I remember correctly) is that a dynamically typed language
puts type on values whereas a statically ditto puts them on
variables/identifiers.

It seem to make sense: Foo can be either an integer(), an atom() or a
string(), so no type is associated with the Foo identifier. On the
other hand, 37 is an integer(), trap_exit an atom() and "Hello
Lambda!" a string(). In a statically typed language, Foo would have
had a specific type declaring, e.g., "Foo :: integer()" so "Foo can
only contain integers!!!".

Type theorists tend to call dynamically typed languages for *untyped*
languages. The correct term is perhaps trivially typed, for we can
invent a "magical" type τ and proceed to give every expression in the
language this type τ. What is τ you ask? Well, it is any primitive or
compound value you can validly form in the programming language. We
have thus just added a type system to the language - albeit a trivial
one and in this sense, all programming languages are typed. Our
magical τ has a big shortcoming however: If a program is well-typed,
we can't say anything about it at all! In contrast, with statically
typed programs we tend to have certain properties (called
meta-theoretic properties) of programs that *passes* a type check.
Most often it has something to do with the idea that you can't
accidentally form certain invalid statements, like for instance the
expression '37 + trap_exit' which has no meaning. We tend to like the
term 'untyped' but really we mean 'programming language with no type
system guarantees'.

In general, I don't think it is interesting to classify a language as
being dynamic by claiming a broad group of features a dynamic language
must have to be called such. Rather I'd recommend that you look at
each of those features you mentioned, metaprogramming, code injection,
..., in isolation and look for languages that have each individual
component.

-- 
J.


More information about the erlang-questions mailing list