Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1928046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:55:55+00:00 2026-05-17T06:55:55+00:00

For my logging I wanted the ability to macro out the statements at compile

  • 0

For my logging I wanted the ability to macro out the statements at compile time, so -define to the rescue!

For my compiler flags I’m compiling with erlc -DFOO, is there a way for -ifdef to determine the difference between FOO = ok, FOO/0, and FOO/1?

-module(foo).

-define(FOO, ok).
-define(FOO(X), io:format("~p~n", [X])).

-export([test_x/1]).

%% i want this to be true iff FOO = ok, not if ?FOO/1 exists
-ifdef(FOO).
test_x(X) ->
    ?FOO(":) " ++ X).
-else.
test_x(X) ->
    ?FOO(":( " ++ X).
-endif.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:55:55+00:00Added an answer on May 17, 2026 at 6:55 am

    I had better write a fuller reply.

    No, there is no way to test the actual macro definition, you can only test if a macro with that name has been defined. And you can only test on the macro name, not on alternative macro definitions with different arities. This is relic from the past, before R13B, when you could only have one macro definition per name. The new one more closely mimics functions in a module.

    The “standard” way of doing it is to use some flag macro to determine which set of macros/functions to use. For example:

    -ifdef(DEBUG).
    
    -define(DEBUG_PRINT(X), <... something long here ...>).
    foo(X) -> <... debuggy stuff here ...>.
    
    -else
    
    -define(DEBUG_PRINT(X), ok).
    foo(X) -> <... normal stuff here ...>.
    
    -endif.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to keep my logging statements as short as possible while preventing console
I am planning to used audit logging plugin in grails and just wanted to
When logging out or sending (to a web service using RestKit) specifically the subThoroughfare
Ok I have another question HERE for my Logging Class but I wanted to
I wanted to ask for some logging mechanism or framework with specific function. I
I will try to explain the question again: I wanted to introduce logging in
I am logging errors on my asp.net-mvc site and I wanted to see if
I'm starting this new project and we are thrashing out our logging/debugging approach and
I am using Apache Commons Logging ™ . For now I wanted to use
We're recently switched over to Log4J from JUL (java.util.Logging) because I wanted to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.