Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preprocessor Directives: #elif missing #17282

Closed
Thorium opened this issue Jun 6, 2024 · 3 comments
Closed

Preprocessor Directives: #elif missing #17282

Thorium opened this issue Jun 6, 2024 · 3 comments

Comments

@Thorium
Copy link
Contributor

Thorium commented Jun 6, 2024

F# seems to have #elif preprocessor directive / pragma missing:
https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/compiler-directives#preprocessor-directives

C# has it:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives#conditional-compilation

I know it's not good practice to use lot of these, I'm not trying to do a templating engine, I would just like to do a simple switch like this:

[<Literal>]
let myPath =
#if WIN64
  "/library/x64/runtime.dll"
#elif WIN86
  "/library/x86/runtime.dll"
#elif MAC
  "/library/iOS/runtime-osx.dll"
#else
  "/library/unix/runtime.dll"
#endif

The current workaround:

[<Literal>]
let myPath =
#if WIN64
  "/library/x64/runtime.dll"
#endif 
#if WIN86
  "/library/x86/runtime.dll"
#endif 
#if MAC
  "/library/iOS/runtime-osx.dll"
#endif 
#if !WIN64 && !WIN86 && !MAC
  "/library/unix/runtime.dll"
#endif
@abelbraaksma
Copy link
Contributor

abelbraaksma commented Jun 6, 2024

I think this is a reasonable suggestion, can you copy this over to https://github.com/fsharp/fslang-suggestions? It is where suggestions go and can be upvoted. It is used for suggestions that require a language, core lib or syntax change. If accepted by Don, we will then proceed with an RFC and, hopefully, an implementation.

Note that there's some prior discussion here: fsharp/fslang-suggestions#273 (if you look at the archived comments, you can see that that was still from the F# 4 days in Codeplex. The design of the time is gone, but clearly, the part that says #elif didn't make it into the language at the time).


edit, note that #if can be nested, so your code example may be easier if turned into this:

let myPath =
#if WIN64
    "/library/x64/runtime.dll"
#else
    #if WIN86
        "/library/x86/runtime.dll"
    #else
        #if MAC
            "/library/iOS/runtime-osx.dll"
        #else
            "/library/unix/runtime.dll"
        #endif
    #endif
#endif

(I mean, it would be easier to read with your suggestion, but at least you won't need the complex boolean expressions)

@abelbraaksma
Copy link
Contributor

Closing this, as it is now here: fsharp/fslang-suggestions#1370

@abelbraaksma abelbraaksma closed this as not planned Won't fix, can't repro, duplicate, stale Jun 6, 2024
@KevinRansom
Copy link
Member

#elif is an excellent suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants