I notice that each time I open F# Interactive (FSI) from within Visual Studio to tryout something REPL-style, I always find myself executing a few commands first, often specific for any given project:
open System;;
#r #"r:\projects\currentprjLibs.dll";;
#r #"r:\external\unquote.dll";;
#time;;
This is just an example, but I find myself asking: can this be automated? Now, I could have an fsx script for each project and do a "send to interactive", but this is still quite a bit of work (and #r or #time won't work there). Besides, I have to do it again on each FSI Reset.
Does anybody know of a simpler way? Should I roll my own (I never created a serious add-in for Visual Studio, but maybe now is a good time). Other suggestions?
PS: the solution here is not what I am after, as it applies to every instance of FSI and it doesn't do opens. The 2nd solution there is to add #if INTERACTIVE, but this adds clutter, is difficult to write with relative paths, and Ctrl-A plus Ctrl+Shift+Enter will choke on any namespace, which then also needs to be in #if !INTERACTIVE, adding more clutter.
Related
Is there a tool that detects unused code in F# programs?
Tools for F# have been discussed from time to time, but it has been a while since this question:
Are there any support tools like coderush or resharper for F#?
I don't know of any tool that performs dead code analysis for F# right now.
That said, the recently-released FSharp.Compiler.Service project certainly makes implementing such tools easier now.
A while back, one or two of the JetBrains developers experimented with a ReSharper language service for F#, but I don't think they ever got to the point where it was usable in production. Maybe now that FSharp.Compiler.Service is available, perhaps work can start up again. If you want to see their work: https://github.com/JetBrains/FSharper
Use the following project settings:
Visual Studio > Solution >
Project > Build > General > Other flags > --warnon:1182
This will warn on unused functions and values when code gets compiled.
Is there a REPL for Dart to experiment with?
I tried inputing dart code in DevTools in Dartium and that also didn't work.
So I couldn't find an easy way to play with various APIs in dart.
I tried inputing dart code in devtools in Dartium and that also didn't
work.
I'm very new to Dart, but something I came across was that you CAN evaluate code in Dartium. In order to do so, you must first load a page with Dart code in it and then toggle this selector in the console from "javascript page context" to one that references a Dart package or Dart code.
Once you do that you should be able to execute Dart in the console:
As a VIM user, I hardly have to open the Dart Editor now :). I should also mention that breakpoints, hovering over stepped into code to get variable details, navigating the call stack, and some level of intellisense in the console also work. I couldn't get conditional breakpoints to work, though.
Though it is not really a REPL, you may find the Try Dart online tool useful for playing around. It's a bit slow, since it is actually compiling the Dart code to JavaScript in order to have it work within the browser.
There is also a console that someone built, which is probably better if you're looking for a real REPL, but it requires a bit of setup.
There is an announcement about REPL for Dartium - see Nathanial's comment below. There are plans for Smalltalk like super-REPL. Here is what Gilad Bracha (member of the Dart team at Google) wrote on this subject in Is there a REPL or console for Dart:
"I don't see this as a language question at all. It is a matter of tooling and reflective library support. With proper mirror builder APIs, building a REPL would be trivial. As it sands right now, it can be quite challenging. And of course, REPL is not the ultimate goal - there are more advanced interactive tools, like workspaces in Smalltalk/Self/Newspeak, where you not only evaluate things interactively at some top level, but can inspect the resulting objects, evaluate within the scope of an individual declaration or object etc. I am sure we will get there in time - and i much prefer sooner than later."
The correct answer is https://dartpad.dev/
That site didn't exist when the other answers were posted in 2013, but you've stumbled on this post after 2020. And now you know. https://dartpad.dev allows you to create and share new Dart snippets and even put them in a Flutter app running online. Very, very cool!
Since 2022.10.22, there is a REPL for Dart: https://github.com/fzyzcjy/dart_interactive :)
Features:
Use any third-party package freely
Auto hot-reload code anywhere, with state preserved
Supports full grammar in REPL
Play with existing code side-by-side
Disclaimer: I wrote that package.
When using F# interactive apparently this line of code will search in the path shown in the subject line.
let files = Directory.GetFiles("MyFolderPath")
Is there any way to set interactive to search the same folder the current fsx file is running from? Or any way to control this behavior at all? I'm used to the search starting in bin\Debug obviously and this behavior is throwing me off.
Thanks in advance,
Bob
It depends from where the process fsi.exe is started. Fsi is separated from the IDE, it doesn't know which file is open. When you run Visual Studio, the current directory for fsi is the temp folder.
If you run the fsx file (fsi foo.fsx or right-click "Run with F# Interactive"), fsi will run from current directory.
To see where you are (in which directory), you can do:
Directory.GetCurrentDirectory()
To change directory, use this command:
Directory.SetCurrentDirectory(...)
F# interactive is completely independent of the current F# program (in fact, think of it as running in a separate CMD shell). So I'm afraid, there won't be a simple way to get the currently opened .fsx file.
You might be able to pull something from fsi.CommandLineArgs but I have no VS at hand to confirm this.
I would like to add an F# REPL to my application for live debugging purposes. I am looking at the source code for fsi.exe (F# Interactive) and there is a ton of stuff going on that looks like it pokes around with F# compiler internals. I cannot get this same code to compile in the context of our application because of this.
Is there a nice simple example of implementing an F# REPL somewhere? I would have hoped for this to be fairly easy.
The short answer is that F# (unfortunatelly) doesn't currently provide any API for hosting F# Interactive in your applications. There are a lot of people asking for this - see for example this SO question.
There are essentially two things you could do about that:
You can modify the open-source release and compile fsi.exe as some DLL library that would provide the API you need. This isn't simple task - F# Interactive is tightly bound with the compiler (it compiles code you enter on the fly), but it should be doable to encapsulate the types implementing REPL into some type you could call (But you cannot just take some file out of it - you need to compile entire F# to get this working).
You can run fsi.exe as a separate process as Visual Studio does and send commands to it using standard input/output. You can get some more flexibility by loading your library when fsi.exe starts. The library could use .NET Remoting to connect back to your application and expose some data.
Unfortunatelly, these two options are probably the only things you can do at the moment.
EDIT I was thinking that I already answered this question somewhere (perhaps in email), but couldn't
find it! Thanks to Mauricio who found the exact duplicate (even with my duplicate answer... Doh!)
I've written a series of blog posts about using the open source F# interactive executable inside and WPF application.
The code base is available on github - https://github.com/oriches/Simple.Wpf.FSharp.Repl
The series of blog posts are:
http://awkwardcoder.blogspot.co.uk/2013/12/simple-f-repl-in-wpf-part-1.html
http://awkwardcoder.blogspot.co.uk/2013/12/simple-f-repl-in-wpf-part-2.html
http://awkwardcoder.blogspot.co.uk/2013/12/simple-f-repl-in-wpf-part-3.html
The final post is to follow soon.
I made a class library, and put it in GAC.
It has one C# code file, and I put a Console.WriteLine() statement in.
When I run the Feature, where would I see the output from this statement?
Use
System.Diagnostics.Trace.WriteLine()
or
System.Diagnostics.Debug.WriteLine()
(Will only output text if assembly
compiled in debug mode)
to output some text. You would then see it in a program like DebugView.
But the best way to debug the program (if you ask this question regarding to debugging) i recommend attachking to SharePoint with Visual Studio debugger. Some debugging tips here.