Quantcast
Viewing latest article 1
Browse Latest Browse All 2

Answer by Steve Vinoski for Top level assignment

There are no global variables in Erlang. You can use a function instead, like this for example:

-module(test).-export([main/0]).x() ->    1.main() ->    io:format("~p~n", [x()]).

For something as simple as a literal 1 you could also define a preprocessor macro, like this:

-define(X, 1).main() ->    io:format("~p~n", [?X]).

but given that your question mentions higher-order functions, you probably don't want to use the preprocessor.


Viewing latest article 1
Browse Latest Browse All 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>