পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Tuesday, January 31, 2017

Erlang - Macros

Macros are generally used for inline code replacements. In Erlang, macros are defined via the following statements
  • -define(Constant, Replacement).
  • -define(Func(Var1, Var2,.., Var), Replacement).
Following is an example of macros using the first syntax −

Example

-module(helloworld). 
-export([start/0]). 
-define(a,1). 

start() -> 
   io:fwrite("~w",[?a]).
From the above program you can see that the macro gets expanded by using the ‘?’ symbol. The constant gets replaced in place by the value defined in the macro.
The output of the above program will be −

Output

1
An example of a macro using the function class is as follows −

Example

-module(helloworld). 
-export([start/0]). 
-define(macro1(X,Y),{X+Y}). 

start() ->
   io:fwrite("~w",[?macro1(1,2)]).
The output of the above program will be −

Output

{3}
The following additional statements are available for macros −
  • undef(Macro) − Undefines the macro; after this you cannot call the macro.
  • ifdef(Macro) − Evaluates the following lines only if the Macro has been defined.
  • ifndef(Macro) − Evaluates the following lines only if Macro is undefined.
  • else − Allowed after an ifdef or ifndef statement. If the condition was false, the statements following else are evaluated.
  • endif − Marks the end of an ifdef or ifndef statement.
When using the above statements, it should be used in the proper way as shown in the following program.
-ifdef(<FlagName>).

-define(...).
-else.
-define(...).
-endif.

No comments:

Post a Comment