Thread overview
pragmas for expressions?
Oct 22, 2008
mgen
Oct 22, 2008
Gregor Richards
Oct 22, 2008
Ary Borenszweig
Oct 23, 2008
mgen
Oct 23, 2008
BCS
Oct 23, 2008
Robert Fraser
October 22, 2008
I have been hacking into the front end as of late and noticed that pragmas cannot be introduced as parts of expressions and instead must be used as a separated statements. My main concern here is sometimes I wish to set up a value that could be returned and used by the code at compile time; for example:

pragma(msg,"you do not have a version set up... please select unix, linux, windows, or mac by entering the name and pressing enter");
char[] response = pragma(readln);

which could ease the use of things especially build scripts having odd errors that could be corrected at compile time instead of having an entire rerun of the script.

All in all I was wondering what people thought of using pragmas inside of expressions?
October 22, 2008
mgen wrote:
> I have been hacking into the front end as of late and noticed that pragmas cannot be introduced as parts of expressions and instead must be used as a separated statements. My main concern here is sometimes I wish to set up a value that could be returned and used by the code at compile time; for example:
> 
> pragma(msg,"you do not have a version set up... please select unix, linux, windows, or mac by entering the name and pressing enter");
> char[] response = pragma(readln);
> 
> which could ease the use of things especially build scripts having odd errors that could be corrected at compile time instead of having an entire rerun of the script.
> 
> All in all I was wondering what people thought of using pragmas inside of expressions?

Pragmas in expressions: Could be useful, but I'd have to see a good use case.

The use case you provided: Disgusting, offensive, makes me want to find you and break your fingers. Compilation is a NON-INTERACTIVE PROCESS. Repeat that to yourself.

 - Gregor Richards
October 22, 2008
Gregor Richards wrote:
> mgen wrote:
>> I have been hacking into the front end as of late and noticed that pragmas cannot be introduced as parts of expressions and instead must be used as a separated statements. My main concern here is sometimes I wish to set up a value that could be returned and used by the code at compile time; for example:
>>
>> pragma(msg,"you do not have a version set up... please select unix, linux, windows, or mac by entering the name and pressing enter");
>> char[] response = pragma(readln);
>>
>> which could ease the use of things especially build scripts having odd errors that could be corrected at compile time instead of having an entire rerun of the script.
>>
>> All in all I was wondering what people thought of using pragmas inside of expressions?
> 
> Pragmas in expressions: Could be useful, but I'd have to see a good use case.
> 
> The use case you provided: Disgusting, offensive, makes me want to find you and break your fingers. Compilation is a NON-INTERACTIVE PROCESS. Repeat that to yourself.
> 
>  - Gregor Richards

I think it can be very amusing. Some example messages:
 - lol, I think you forgot a semicolon there. This is the time number 2345 you do this, you keep surprising me! Do you want me to add that for you?
 - Hmm... it seems this is taking too much. Would you like to play Tetris meanwhile? Maybe remove some random pieces of code to speed up things?
October 23, 2008
> The use case you provided: Disgusting, offensive, makes me want to find you and break your fingers. Compilation is a NON-INTERACTIVE PROCESS. Repeat that to yourself.
> 
>   - Gregor Richards

Compilation may be non-interactive in your mind but I see it as being similair to build scripting when you do CTFE or some kind of computation. Having the option to do interesting things such as check and correct things instead of completely rebuilding does not seem like something that should just be thrown away because of your ideals that compilation is done without any interaction. Other uses could be a pragma for JiT eval of complex functions to return the structures of a parser without resulting to struct hacks which are a horrible idea. I see this as a logical step to integrate tools into compilation instead of having 2 separated programs.
October 23, 2008
mgen wrote:
> I have been hacking into the front end as of late and noticed that pragmas cannot be introduced as parts of expressions and instead must be used as a separated statements. My main concern here is sometimes I wish to set up a value that could be returned and used by the code at compile time; for example:
> 
> pragma(msg,"you do not have a version set up... please select unix, linux, windows, or mac by entering the name and pressing enter");
> char[] response = pragma(readln);
> 
> which could ease the use of things especially build scripts having odd errors that could be corrected at compile time instead of having an entire rerun of the script.
> 
> All in all I was wondering what people thought of using pragmas inside of expressions?

The general statement of pragmas for expressions is interesting, especially as far as compiler intrinsics are concerned.

For your specific use case, use an import expression. With some pipe trickery in your build scripting, it might be possible to _actually_ make that compilation interactive using import expressions ;-P
October 23, 2008
>Reply to mgen,
>
>>> The use case you provided: Disgusting, offensive, makes me want to
>>> find you and break your fingers. Compilation is a NON-INTERACTIVE
>>> PROCESS. Repeat that to yourself.
>>> 
>>> - Gregor Richards
>>> 
>> Compilation may be non-interactive in your mind but I see it as being
>> similair to build scripting when you do CTFE or some kind of
>> computation. Having the option to do interesting things such as check
>> and correct things instead of completely rebuilding does not seem like
>> something that should just be thrown away because of your ideals that
>> compilation is done without any interaction. Other uses could be a
>> pragma for JiT eval of complex functions to return the structures of a
>> parser without resulting to struct hacks which are a horrible idea. I
>> see this as a logical step to integrate tools into compilation instead
>> of having 2 separated programs.
>> 

I'm not saying your wrong (or right) but there is a HUGE amount of tradition you want to go against. 

A much more approachable idea would be to have the compiler spit out sed commands that would fix compile errors. 

Right now it would be possible to have code print out messages about how to set features.

> pragma(is(typeof(some_const_flag)), "some_const_flag must be set");

switch to static if and static assert and you might be able to get more than one at a time.