[erlang-questions] erlang / laziness
Jesper Louis Andersen
Sun Mar 2 15:15:26 CET 2014
On Sun, Mar 2, 2014 at 12:32 PM, t x <txrev319@REDACTED> wrote:
> I'm from a clojure background, where many things are lazy by
> default, including fundamental constructs, like map.
> (def x (map func lst))
> ;; func is not called on lst yet
In erlang, this would be:
[Func(L) || L <- list()].
The evaluation will happen when x/0 is invoked, but in Erlang the
evaluation order is strict by default and nothing is evaluated "on demand"
unless you explicitly ask for an iterator-like construct. Clojure also uses
a strict evaluation order, but many data structures are consumed by
iteration in Clojure and this means you have a way to terminate a
computation in the middle of a map by not demanding the full sequence.
> [ func(X) || X <- Lst],
> Is this assumption correct?
In the above, you essentially have three Expressions
The rule in Erlang is that they are evaluated in order, i.e., E1 before E2
before E3. And they are always evaluated for their eventual effect, even if
you don't bind the result.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions