The Full Wiki

More info on Erlang Programming/Macros

Erlang Programming/Macros: Wikis

Advertisements

Note: Many of our articles have direct quotes from sources you can cite, within the Wikipedia article! This article doesn't yet, but we're working on it! See more info or our list of citable articles.

Wikibooks

Up to date as of January 23, 2010

From Wikibooks, the open-content textbooks collection

< Erlang Programming

Macros

-define(LIKERT_SCALE, lists:seq(1, 5)). 

A = ?LIKERT_SCALE.

The code makes A = [1,2,3,4,5].

Some handy predefined macros include:

 ?MODULE  (module name)
 ?LINE    (line number)
 ?FILE    (filename as a string)
 % ===========================================
 % Example code
 % ===========================================
 -module(test_macros).
 -define(LIKERT_SCALE, lists:seq(1, 5)).
 -compile(export_all).
 
 start() ->
   io:format("likert scale:  ~w \n", [?LIKERT_SCALE]),
   io:format("module name:   ~w \n", [?MODULE]),
   io:format("line number:   ~w \n", [?LINE]),
   io:format("filename:      ~s \n", [?FILE]),
   ok.
 % ===========================================
 % Example output
 % ===========================================
 %
 % 6> c(test_macros).
 % {ok,test_macros}
 % 7> test_macros:start().
 % likert scale:  [1,2,3,4,5] 
 % module name:   test_macros 
 % line number:   10 
 % filename:      ./test_macros.erl
 % ok

Advertisements






Got something to say? Make a comment.
Your name
Your email address
Message