On Aug 8, 11 05:56, bearophile wrote:
KennyTM~:
So I go for my 2nd alternative, which is to add a magic function __ctfeWriteln
that does the same.
In my implementation, __ctfeWriteln will print the interpreted arguments
to stdmsg when CTFE-ed, and is a no-op in runtime (it can be configured
to throw an exception or actually print the arguments or anything you like).
Important: if there is a single function then I do *not* want it to print a
newline. Adding a newline when you need it is much simpler than removing it if
you do not want it. If you really want a newline too, then create two
functions, (similar to write and writeln), but the most important is the one
without newline.
What's the purpose of the two leading underscores? I prefer it without them. This is
supposed to be a clean and nice function, not an unsafe ugly thing :-) So I think a
"ctfeWrite" name is better.
Two leading underscores means it's a reserved identifier which should
have no chance of collision. It does not mean unsafe. Also, it's named
after the existing identifier '__ctfe'.
Generally I'd like this functions to print equally at compile-time and
run-time, but I see there are some problems in doing this...
If the function"ctfeWrite" becomes too much complex (to print arbitrary
things), then for me it's acceptable it to print just strings too (with no newline added).
__ctfeWrite is not complex, but I don't see the need for it.
Bye and thank you for your work,
bearophile