[erlang-questions] Stringification in erlang macros

Maxim Treskin zerthurd@REDACTED
Wed Sep 24 15:14:01 CEST 2008


Hello

Is it possible to stringify macros argument in erlang? In cpp we have
#EXPR which replaces with string value of EXPR. I wrote something like
this using parse_transform, but it is ugly, requires too much
workarounds for works in every place in code and almost not works :)
For example I want:

-define(ASSERT(Cond), if '$@'(Cond) -> ok; true -> io:format("[~w:~b]:
Assertion: ~p~n", [?MODULE, ?LINE, '$#'(Cond)]) end).

and code like:
?ASSERT(asd =:= 123)

will prints:
[mod:432]: Assertion: "asd =:= 123"


Also, is there any right method to put asserts or my idea is wrong in base?

Thank you.

-- 
Maxim Treskin



More information about the erlang-questions mailing list