Quantcast
Channel: Top level assignment - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Steve Vinoski for Top level assignment

$
0
0

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 all articles
Browse latest Browse all 2

Trending Articles



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