[erlang-questions] Process scope variable
Anthony Ramine
n.oxyde@REDACTED
Tue Feb 17 23:49:39 CET 2015
Le 17 févr. 2015 à 14:55, Imants Cekusins <imantc@REDACTED> a écrit :
> Does anyone see any benefit from process scope variables?
>
> E.g.
> a()->
> A = 10,
> b().
>
> b()->
> B = A + 1.
>
> If unset variable is referenced, an error is raised.
>
> If set process variable is assigned to (and does not pattern match),
> an error is raised.
>
>
> This way, there is no need to pass a bunch of static variables around.
Just use a pmod [1]!
le_malaise.erl:
-module'le_malaise',[A].
-compile{parse_transform,pmod_pt}.
-export[b/0].
b() -> A + 1.
le_malade:erl.
-module'le_malade'.
-export[test/0].
test() ->
(le_malaise:new(10)):b().
[1] https://github.com/erlang/pmod_transform
More information about the erlang-questions
mailing list