REPL for the Dart language
Asked Answered
I

5

29

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.

Iquique answered 7/8, 2013 at 17:23 Comment(1)
Since 2022.10.22, there is a REPL for Dart: github.com/fzyzcjy/dart_interactive (disclaimer: I wrote that package)Inexertion
P
6

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.

Purulent answered 7/8, 2013 at 18:0 Comment(2)
I tried to build dart-console but I don't think its compatible with the new dart-sdk [0.6.15.3_r25822].Iquique
I noticed that there is an issue on google code for it.Iquique
P
14

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.

enter image description here

Once you do that you should be able to execute Dart in the console:

enter image description here

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.

Philipp answered 5/2, 2014 at 19:53 Comment(2)
Excellent, that looks very encouraging.Gytle
Different from a JavaScript console, you cannot define class or function in the console. It seems to be in a context similar to a function body (so you can still create lambdas).Coo
P
6

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.

Purulent answered 7/8, 2013 at 18:0 Comment(2)
I tried to build dart-console but I don't think its compatible with the new dart-sdk [0.6.15.3_r25822].Iquique
I noticed that there is an issue on google code for it.Iquique
A
5

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."

Add answered 23/10, 2013 at 23:6 Comment(3)
According to news.dartlang.org, Dartium got a REPL on the 2nd of this month. That being said, I can't seem to find it. Just typing dart into the console doesn't seem to work for me, even at break points. news.dartlang.org/2013/10/…Shurwood
@Shurwood You are right, it mentions REPL. I better edit my answer.Add
Ok so this a long time between comments, but thank you @Shurwood for the pointer to that article. The REPL mentioned there is just expression eval on breakpoints which has no been available for a long time in the Dart debugger, but the magic tidbit in that article is that you can use JS style IIFE to execute which is super useful!Colt
B
1

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!

enter image description here

Bonucci answered 10/1, 2020 at 21:40 Comment(3)
Nice one, however a REPL it is not :-(Corkscrew
What? What am I missing? Read-Evaluate-Print-Loop... check, check, check, and check. Educate me, please, @EricPlaton. :-)Bonucci
@Bonucci Dartpad is a very nice tool, but it is not a REPL. It does not maintain state as a REPL is expected too, nor does it read input nor evaluate/print Dart code in a loop. It is simply a text editor+Dart compiler and then runs the compiled code, which is completely different to a REPL.Colt
I
1

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.

Inexertion answered 23/10, 2022 at 3:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.