-
Notifications
You must be signed in to change notification settings - Fork 123
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
Introduce #use
API in FCS (#load with fragment-by-fragment evaluation)
#621
Comments
Appending The only way I could make it work was: let scriptContents =
sprintf "#line 1 @\"%s\"\n" scriptFile +
System.IO.File.ReadAllText scriptFile +
"\n()"
x.EvalInteraction scriptContents Not sure if this is the recommended way of doing things. |
@matthid If I start
then we get the same behaviour as "Actual" above - so EvalInteraction is just doing what fsi.exe has always done. So it looks like the correct behaviour for EvalInteraction given that input. Note that fsc.exe and
|
Question is: How can I do the same? |
From the behaviour you report above in the "Actual" section it looks to me like
Perhaps I don't understand what you mean by a "real" #load. EvalScript is the equivalent of a #load. EvalInteraction is the equivalent of using the input text as an interaction (incuding If you want the latter (sometimes called "#use" on a script, rather than "#load" - FSI doesn't support the |
This is related to dotnet/fsharp#1392. I want to have a dotnet/fsharp#1392 (comment) suggest using |
@matthid OK, so this is a feature request for FCS right? You're after a behavior that can't be done with either F# Interactive or the F# compiler today? Specifically, you want an EvalInteraction that doesn't actually run the initialization code of the interaction but instead just checks/compiles it and then uses on-demand initialization? If so, could you explain the scenario a bit more to help me understand what's driving the feature request. It sounds like it would be a "don't evaluate eagerly" flag on EvalScript and EvalInteraction. |
I'm not sure.
Ideally I'd like to see this implemented in the compiler (see Use case 1 below).
No. It can already be done. It's just Maybe it makes more sense after the use cases... Use case 1:Consider having two scripts which use Paket or nuget to bootstrap (note: this is untested dummy code): // ...
webClient.Download("nuget.client.dll")
#r "nuget.client.dll"
Nuget.Client.Restore("deps.config")
// .. more restore action
#r "package1.dll"
#r "package2.dll"
#r "package3.dll"
// Regular script logic of test1.fsx
// Use other interactive directions like #cd and stuff
// ...
webClient.Download("nuget.client.dll")
#r "nuget.client.dll"
Nuget.Client.Restore("deps.config")
// .. more restore action
#r "package1.dll"
#r "package2.dll"
#r "package3.dll"
// Regular script logic of test2.fsx
// Use other interactive directions like #cd and stuff Now you want to "extract" the common bootstrapping logic to a shared script -> Doesn't work with Use case 2Consider |
@matthid Thanks Ah OK, thanks The primary FCS issue seems to be that EvalInteraction doesn't do fragment-by-fragment evaluation. Let's change this issue to cover that . That should be simple enough to fix. The Yes this means you can't factor out common fragments of scripts that create DLLs etc. I think the right thing is to propose on fslang.uservoice.com to add a A key question is how the type checker in Visual Studio, Xamarin etc. would treat the Cheers |
Thanks for the detailed answer! Now we managed to get to the root problem :)
I assumed something like that, but couldn't figure out why...
That discussion is now over with One note after reading your answer: If we can't handle it in the tooling I'm actually against introducing |
#use
API in FCS (#load with EvalInteraction semantics)
#use
API in FCS (#load with EvalInteraction semantics)#use
API in FCS (#load with fragment-by-fragment evaluation)
Yes, that's part of the thinking too.
We can just add it to FCS - It's reasonable for EvalInteraction to effectively be a multi-fragment |
@dsyme Thanks. I'm fine with that. Will try to hack something together :) (Can take some days/weeks though) |
@dsyme Continuation from dotnet/fsharp#1392
Repro steps
test.fsx
failwith "test"
Expected behavior
Actual behavior
Related information
This should be a workaround to properly load a script with interaction directive support, but its not working.
Should I add the string "; ();;" to the script contents? This turns out to be more like a hack than a solution.
The text was updated successfully, but these errors were encountered: