Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does F# Interactive #I command know about project path?

Here is the scenario:

  1. Open Visual Studio. This was done in VS2010 Pro.
  2. Open F# Interactive within Visual Studio
  3. Open project with fsx file
    Note: Project and fsx file are in E:\<directories>\fsharp-tapl\arith
  4. Send commands to F# Interactive from fsx file

    > System.Environment.CurrentDirectory;; 
    val it : string = "C:\Users\Eric\AppData\Local\Temp"
    

    I was not expecting a Temp directory but it makes sense.

    > #r @"arith.exe"
    Examples.fsx(7,1): error FS0082: Could not resolve this reference. 
    Could not locate the assembly "arith.exe". 
    Check to make sure the assembly exists on disk. 
    If this reference is required by your code, you may get compilation errors. 
    (Code=MSB3245)
    
    Examples.fsx(7,1): error FS0084: Assembly reference 'arith.exe' was not found 
    or is invalid
    

    The #r command error shows that F# Interactive currently does not know the location of arith.exe.

    > #I @"bin\Debug"
    --> Added 'E:\<directories>\fsharp-tapl\arith\bin\Debug' 
    to library include path
    

    So we tell F# Interactive the location of the arith.exe. Notice that the path is NOT an absolute path but a sub-path of the project. I have not told F# Interactive the location of the arith project E:\<directories>\fsharp-tapl\arith

    > #r @"arith.exe"
    --> Referenced 'E:\<directories>\fsharp-tapl\arith\bin\Debug\arith.exe'
    

    And F# Interactive correctly finds arith.exe reporting the correct absolute path.

    > open Main
    > eval "true;" ;;
    true
    val it : unit = ()
    

    This confirms that arith.exe was correctly found, loaded and works.

So how did F# Interactive #I command know the project path since the current directory is of no help?

What I am really after is from within F# Interactive how does one get the path to the project, E:\<directories>\fsharp-tapl\arith.

EDIT

> printfn __SOURCE_DIRECTORY__;;
E:\<directories>\fsharp-tapl\arith
val it : unit = ()
like image 926
Guy Coder Avatar asked Feb 03 '13 14:02

Guy Coder


People also ask

What does f mean in math?

more ... A special relationship where each input has a single output. It is often written as "f(x)" where x is the input value.

What is the formula of f x?

The slope of a linear function is calculated by rearranging the equation to its general form, f(x) = mx + c; where m is the slope. The vertex of a quadratic function is calculated by rearranging the equation to its general form, f(x) = a(x – h)2 + k; where (h, k) is the vertex.

Does f mean derivative?

We can then define a function that maps every point x to the value of the derivative of f at x. This function is written f′ and is called the derivative function or the derivative of f. Sometimes f has a derivative at most, but not all, points of its domain.


1 Answers

In F# Interactive, the default directory to search is the source directory. You can query it easily using __SOURCE_DIRECTORY__.

This behaviour is very convenient to allow you to use relative paths. You often have fsx files in the same folder with fs files.

#load "Ast.fs"
#load "Core.fs"

When your refer to a relative path, F# Interactive will always use the implicit source directory as the starting point.

#I ".."
#r ... // Reference some dll in parent folder of source directory
#I ".."
#r ... // Reference some dll in that folder again

If you want to remember the old directory for next reference, you should use #cd instead:

#cd "bin"
#r ... // Reference some dll in bin
#cd "Debug"
#r ... // Reference some dll in bin/Debug
like image 157
pad Avatar answered Nov 16 '22 03:11

pad