dart_repl 0.11.1

  • README.md
  • Installing
  • Versions
  • 3



A proof of concept REPL environment for Dart.

asciicast asciicast

See the Dart REPL Directions brain-dump for possible ideas and directions.


pub global run

You can install and setup dart_repl using:

pub global activate dart_repl

To run it, simply execute:

pub global run dart_repl

If you run it from a directory that contains a Dart package (it needs a .packages file), it will load all dependencies automatically and allow you to import libraries adhoc from the command-line:

pub global run dart_repl --adhoc-import package:built_collection/built_collection.dart

(if your package depends on built_collection).

Alternatively, you can use the import() builtin command instead of the commmand-line flag --adhoc-import:

$ pub global run dart_repl

>>> import('package:built_collection/built_collection.dart');

This is the preferred way of running dart_repl as it requires no additional setup.

From another package

You can add a dev_dependency: to your pubspec.yaml:


You can then run the REPL with:

pub run dart_repl

It will automatically resolve all additional adhoc imports against the dependencies of your package:

pub run dart_repl --adhoc-import package:built_collection/built_collection.dart

From a checkout

From the command-line

dart bin/dart_repl.dart

To import additional libraries, you need to specify a package directory (--package-dir) to allow it to resolve dependencies:

dart bin/dart_repl.dart --package-dir ~/git/built_collection.dart/ --adhoc-import lib/built_collection.dart

Features requests and bugs

Please file feature requests and bugs at the issue tracker.



[X] provide a back channel for the sandbox to change its own package config. [] find a way to unexport a library (can we enumerate all the symbols from a library and hide them?)

Changes and open questions

Variable shadowing

Variables need to be declared with var or final now. Each top level declaration spawns a new compilation unit. All compilation units are chained together. This means that you can freely redeclare variables. They will shadow each other. This can lead to unintended consequences though:

>>> var a = 1
>>> void ip() { print(a++); }
>>> ip()
>>> ip()
>>> var a = 1;
>>> ip()
>>> a

Old Scope behavior

The old behavior (non-shadowed, undeclared variables) is available using the scratch Scope.

>>> scratch.a = 1
>>> void ip() { print(++scratch.a); }
>>> ip()
>>> ip()
>>> scratch.a = 1
>>> ip()

Why can't I keep this default?

The Scope behavior is ideal, however, I don't know how to lift it into the global namespace. Before I was evaluating every expression and statement within the Scope, so you could access all its fields without qualification. However, with top-level declaration, this is not possible anymore. This would mean having different semantics:

>>> a = 1


>>> class X { void ip() { print(++scratch.a); } }

A solution would be to generate a global scope file that is constantly reloaded. This seems infeasible for more complex inputs and for redefinitions.

Export not import!

Because each top-level decl is its own compilation unit, imports only work within the same cell/input.

>>> import 'dart:io'; get pwd => Directory.current;
>>> pwd
Directory: '/Users/blackhc/IdeaProjects/dart_repl'
>>> Directory.current
Unhandled exception:
NoSuchMethodError: No top-level getter 'Directory' declared.

To make a library available to following cells, you have to use export.

>>>  export 'dart:io'
>>> Directory.current
Directory: '/Users/blackhc/IdeaProjects/dart_repl'



  • Initial version

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  dart_repl: ^0.11.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:dart_repl/dart_repl.dart';
Version Uploaded Documentation Archive
0.11.1 Apr 19, 2017 Go to the documentation of dart_repl 0.11.1 Download dart_repl 0.11.1 archive
0.11.0 Apr 19, 2017 Go to the documentation of dart_repl 0.11.0 Download dart_repl 0.11.0 archive
0.10.0 Apr 19, 2017 Go to the documentation of dart_repl 0.10.0 Download dart_repl 0.10.0 archive
0.9.3 Jan 16, 2017 Go to the documentation of dart_repl 0.9.3 Download dart_repl 0.9.3 archive
0.9.2 Jan 16, 2017 Go to the documentation of dart_repl 0.9.2 Download dart_repl 0.9.2 archive
0.9.1 Jan 16, 2017 Go to the documentation of dart_repl 0.9.1 Download dart_repl 0.9.1 archive
0.9.0 Jan 15, 2017 Go to the documentation of dart_repl 0.9.0 Download dart_repl 0.9.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.0.0 <2.0.0