The most noticeable difference between normal F# source files and F# script files is the usage of compiler directives. These are special hints and commands to the F# compiler.
The following directives are available in any F# source program but are mostly applicable to F# scripts.
The Source Directory directive, available with
returns the current directory of the executing code. This is
especially helpful in scripts for determining where the script file is
located. Any instance of
__SOURCE_DIRECTORY__ will be replaced with a
constant string as soon as the file is compiled:
C:\Program Files\Microsoft F#\v4.0>fsi.exe Microsoft F# Interactive, (c) Microsoft Corporation, All Rights Reserved F# Version 184.108.40.206, compiling for .NET Framework Version v4.0.20620 Please send bug reports to firstname.lastname@example.org For help type #help;; >
__SOURCE_DIRECTORY__;; val it : string = "C:\Program Files\Microsoft F#\v4.0" > #q;; C:\Program Files\Microsoft F#\v4.0>
directive returns the current filename. When you combine this
__SOURCE_DIRECTORY__, you can determine the
actual script being executed.
Example 9-1 runs
a script that prints the
__SOURCE_FILE__ to the console. Like
__SOURCE_FILE__ will be replaced with a
string as soon as the file is compiled.
Example 9-1. Using __SOURCE_FILE__ and __SOURCE_DIRECTORY__
C:\Program Files\Microsoft F#\v4.0>type AweomestScriptEver.fsx ...