3

in a.fsx :

namespace na 
module ma = 
    let var = 2

in b.fsx :

#load "a.fsx"
namespace nb
module mb = 
    let var = na.ma.var

in c.fsx :

#load "a.fsx"
namespace nc
module mc = 
    let var = na.ma.var

in userdep.fsx :

#load "b.fsx"
#load "c.fsx"

in user.fsx:

#load "userdep.fsx"

Now if I send that last instruction from within user.fsx to FSI, I get :

> 
[Loading \\psf\home\Documents\Visual Studio 11\Projects\Library3\Library3\b.fsx
 Loading \\psf\home\Documents\Visual Studio 11\Projects\Library3\Library3\a.fsx
 Loading \\psf\home\Documents\Visual Studio 11\Projects\Library3\Library3\c.fsx
 Loading \\psf\home\Documents\Visual Studio 11\Projects\Library3\Library3\userdep.fsx]


b.fsx(6,15): error FS0039: The namespace or module 'na' is not defined
> 

Which makes sense if the load order decided is the one displayed. If I send the 2 lines from userdep.fsx, then I'd have to reference to a in different namespaces :

> 
[Loading \\psf\home\Documents\Visual Studio 11\Projects\Library3\Library3\a.fsx
 Loading \\psf\home\Documents\Visual Studio 11\Projects\Library3\Library3\b.fsx]

namespace FSI_0002.na
  val var : int


namespace FSI_0002.nb
  val var : int

[Loading \\psf\home\Documents\Visual Studio 11\Projects\Library3\Library3\a.fsx
 Loading \\psf\home\Documents\Visual Studio 11\Projects\Library3\Library3\c.fsx]

namespace FSI_0003.na
  val var : int


namespace FSI_0003.nc
  val var : int

> 

Are there any principles to circumvent that behaviour you are aware of ?

nicolas
  • 9,549
  • 3
  • 39
  • 83
  • 3
    That's not how you're supposed to do things. You are supposed to have module files (`.fs` files), and a single script file which loads all of them in the correct order. Script files should very rarely load other script files. – Ramon Snir Mar 17 '13 at 19:14
  • That is a good guidance. I am looking for a composible way to have independant script access to the functionnality inside of a,b, and c. It is too bad script dont compose out of the box.. – nicolas Mar 17 '13 at 20:57
  • I am not sure this is possible without some compilation steps to resolve the order of loading and make it specific to each combination of features. – nicolas Mar 17 '13 at 21:03
  • If you really cannot redesign your goal, then I suggest writing a meta-script that looks into the smaller scripts (as text files), finds `#load` lines to establish dependencies, then creates new files without the `#load` lines, loads them in the correct order, and deletes the temporary files. Should be almost trivial (one care, is multi-line comments and strings), but at first might seem unaesthetic. – Ramon Snir Mar 17 '13 at 21:08
  • the whole idea would be to have an open system for scripts. that is, Fake taks, but as scripts. that way, no compilation needed, synchro with git, easy contribution. I should have a look at FSI code to see why/how it does that. – nicolas Mar 17 '13 at 21:11
  • As Ramon Snir answered, don't try to load scripts using other scripts. Run your app in one minimal .fsx and define your modules in multiple .fs modules. The other advantage being that you could also compile the .fs files into a dll in the future. Usually, my fsx files are no more than 50 lines of code. – andri Dec 26 '13 at 00:43

0 Answers0