ImportC define attribute

ryuukk_ ryuukk.dev at gmail.com
Thu Aug 29 07:26:17 UTC 2024


On Wednesday, 28 August 2024 at 21:25:47 UTC, Quirin Schroll 
wrote:
> On Saturday, 24 August 2024 at 15:50:14 UTC, ryuukk_ wrote:
>> […]
>> What about an attribute?
>> ```D
>> version(X) @cDefine("ENABLE_X")
>> import lib;
>> ```
>>
>> What do you think?
>
> Like that, it breaks existing grammar semantics. An attribute 
> is also weird; a `pragma` feels much more natural to me. 
> Idiomatic D would require `version` + `else`:
> ```D
> version(X)
> {
>     pragma(define, "ENABLE_X")
>     pragma(define, "X", "1" ~ "2")
>     {
>         import libA : a;
>         import libB : b;
>     }
> }
> else
> {
>     import libA : a
>     import libB : b;
> }
> ```
>
> The argument to `define` must be a string literal (not an 
> expression of type string) that contains exactly an identifier 
> or an identifier followed by comma-separated identifiers in 
> parentheses. The second argument is optional and can be any 
> expression evaluating to a `const(char)[]` at compile-time.
>
> The first requirement isn't necessary for implementing the 
> feature, it just makes sure it's obvious what the code does. 
> The restriction should be lifted, should a compelling use case 
> be found.


I like this idea of using a `pragma` instead

I don't like the version/else

D should lean towards conciseness, not javaness

I refuse, i literally refuse to type these kind of messy code, 
i'll challenge the status quo until i end up switching language

Because so far, it leans towards cementing the status quo, wich 
is sad




More information about the dip.ideas mailing list