Last active
December 21, 2015 13:08
-
-
Save killerswan/6310078 to your computer and use it in GitHub Desktop.
Trouble toggling or not toggling a default function. (How do I do something like Python's `__name__ == "__main__"`?)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #if INTERACTIVE | |
| let args = fsi.CommandLineArgs | |
| if args.[0].Contains("Seq2.fsx") then | |
| // works when run with fsharpi as one bash command | |
| // | |
| // Usage A: | |
| // $ fsharpi Seq2.fsx | |
| main (args.[1..]) | |
| else | |
| // works when loaded and opened in fsi | |
| // | |
| // Usage B: | |
| // $ fsharpi | |
| // > #load "Seq2.fsx";; | |
| // > open Seq2;; | |
| printfn "« not running Seq2 main »" | |
| 0 | |
| #else | |
| #if MAIN_SEQ2 | |
| // works when built with a custom symbol for these compiler directives | |
| // | |
| // Usage C: | |
| // $ fsharpc --define:MAIN_SEQ2 --target:exe Seq2.fsx | |
| // $ mono Seq2.exe | |
| [<EntryPoint; STAThread>] | |
| let demo args = | |
| // although here we also have access | |
| // to System.Environment.GetCommandLineArgs(), | |
| // which also has item 0, too (unlike entrypoint args) | |
| main args | |
| #else | |
| // Usage D: | |
| // $ fsharpc --target:exe OtherThing.fsx | |
| // $ mono OtherThing.exe | |
| #endif | |
| #endif |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well, I suppose I can define a symbol to test with compiler directives like
MAIN_SEQ2and get by, but there's gotta be a more elegant way.