This does not describe an existing feature. It's place to jot down notes for my idea of an @if directive and related features.
Conditional inclusion of source code (aka "conditional compilation") is needed in some circumstances. Some of the better known ones are:
- Adjusting for the back-end (CLR, JVM)
- Demo vs. Production
- Debug or not
- Adjusting for compiler options (-include-tests, etc.)
Other languages including C# (#if, #define) and D (static if, version, ...) have condition compilation features which are taken advantage of by their communities.
General, full form:
@if <condition> <code> @else if <condition> <code> @else <code>
But "@else if" and "@else" are optional and "@else if" can be repeated.
cobra -define:FOO -define:FOO=bar ...
Or in code:
@define FOO @define FOO = 'bar'
And undefining symbols:
cobra -undefine:FOO ...
Or in code:
CLR, CLR20, CLR40, JVM, JVM16, JVM17, JVM18, OBJC, DOTNET, MONO, WINDOWS, UNIX, MAC, ASSERTS, TESTS, CONTRACTS, DEBUG, DST, ERT
... or we could go all lower case:
clr, jvm, objc, dotnet, etc.
- comparison (== <> < > <= >=)
- E1 and E2
- E1 or E2
- not E
- String literal
- ( E )
- Bare Symbol
- Could methods return various kinds of objects instead of just strings? For example, a Version object that does the right thing for comparisons. Or an integer.
- Do we really need access to environment variables? We already have -define.
There is no implementation at this time. If we implement this, it's unlikely that all of it will be implemented at once. However, it would be ideal to complete the design and then to implement a strict subset so that future additions to the language do not break any code.