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.
Related
Usually this is tied to the ctrl+alt+h keybind and available for many other languages but seems to be missing for dart. Find references provides only very basic functionality compared to call hierarchy.
P.S. I did see the SO answer Visual Studio Code show call hierarchy which is true for javascript but not dart.
Edit: This was recently implemented in the Dart language server and will be included in a future Dart/Flutter SDK release.
--- Original Answer ---
The Dart extension/LSP Server does not currently provide an implementation of Call Hierarchy. It's something I did make a start on but hit some snags and haven't gotten back to resolving them yet.
There's an open issue you can subscribe to for updates on this feature here:
https://github.com/Dart-Code/Dart-Code/issues/612
I'm using VS Code with AngularDart. I need to see, what values are inside some variables. Usually one can do that, by setting a breakpoint. But the debugger doesn't seem to work for web projects.
What's the best way to analyse the contents of my variables? How can I do that? Is this a feature that is supported in Webstorm?
I'm using 5.0.0 and Dartium doesn't seem to be supported anymore.
When you use Dart Dev Compiler (DDC) you can use chrome devtools as you would debug any other scripts on the page. The DDC provides source maps so that you can debug the Dart code you would expect, even though DDC is really providing JS underneath.
In this article it says: "The Dart VM reads and executes source code, which means there is no compile step between edit and run.". Does that mean that you can exchange source-code on the fly in a running Dart system like in Erlang? Maybe the compiler is removed from the runtime system and then this is no longer possible. So that's why I'm asking.
Dart is run "natively" only in Dartium, which is a flavour of Chrome with DartVM. When you develop an application you still need to compile it it to JavaScript. This way you get fast development lifecycle and in the end you can compile code to JS. Because it's compiled code there is lots more room for compiler to run optimisations on the code. So from my perspective, the compiler is still there and I don't think you would be able to replace code at runtime.
You can send around source code and run it, but it would need to be in a separate isolate. Isolates do have some relationship to Erlang concepts.
The Dart VM doesn't support hot swapping (Called live edit in V8). However, based on mailing list discussions, it sounds like this is something that the authors do want to support in the future.
However, as the others have mentioned, it is possible to dynamically load code into another isolate.
I am running the latest Chromium build, with the Dart VM. I would like to start playing with Dart's HTML library by messing around with websites, using the Console to enter Dart commands. Obviously, this is easy with Javascript, but I can't work out how to tell the console that I am entering Dart, not JS.
Is this possible?
It is not. I actually requested this feature on the bug tracker a while back but I can't seem to find it. IIRC, it has to do with the fact that you'd have to be running the code within a particular isolate, which at the moment is not possible. In javascript, everything is global so there is a fundamental difference.
It is possible if it has the Dart VM... I run Dartium but I guess that it can be similar!
https://drive.google.com/file/d/0B1XajbEHFd35OFRJSU5hR0FPZlE/edit?usp=sharing
You have to change in the context menu.
If this answer doesn't work for you I'm sorry...
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.