开发者

Conditional compiling in OCaml

suppose I have a long algorithm which I would like to be optionally verbose to debug it. So far I just added many if verbose then printf "whatever" all around the code but this forces the code to execute many useless tests if I don't want to hav开发者_Python百科e it in the verbose mode.

Is there a way to obtain a simple conditional compilation which can just ignore the printf lines if a flag is set?

Something that, for example, I can do in C by using #IFDEF DEBUG printf .. #ENDIF


What you are looking for can be found in camlp4. If you include the predefined macros then you can define flags on the command line using -D (and -U to undef them):

camlp4o pa_macro.cmo -DFOO file.ml

In code it looks like this:

let f x = IFDEF FOO THEN x + 1 ELSE x - 1 END;;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜