dart_repl 0.11.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 47

dart_repl

About

A proof of concept REPL environment for Dart.

asciicast asciicast

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

Usage

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:

dev_dependencies:
  dart_repl:
  [...]

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.

Appendix

TODOs

[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()
1
>>> ip()
2
>>> var a = 1;
>>> ip()
3
>>> a
1

Old Scope behavior

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

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

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
1

but

>>> 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'

Changelog

0.0.1

  • Initial version

1. Depend on it

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


dependencies:
  dart_repl: "^0.11.1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages 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

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Feb 24, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
96 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90 / 100
Overall score:
Weighted score of the above. [more]
47

Platforms

Detected platforms: Flutter, other

Primary library: package:dart_repl/dart_repl.dart with components: io.

Suggestions

  • Fix lib/src/template/isolate.dart.

    Strong-mode analysis of lib/src/template/isolate.dart failed with the following error:

    line: 23 col: 8
    Target of URI doesn't exist: 'sandbox.dart'.

  • Fix issues reported by dartanalyzer.

    dartanalyzer reported 1 error(s) and 0 warning(s).

  • Use constrained dependencies.

    The pubspec.yaml contains 1 dependency without version constraints. Specify version ranges for the following dependencies: vm_service_client.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use dart_repl.dart.

  • Use analysis_options.yaml.

    Rename old .analysis_options file to analysis_options.yaml.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.0.0 <2.0.0
analyzer >=0.29.2 <0.30.0 0.29.11 0.31.1
args >=0.13.7 <0.14.0 0.13.7 1.4.1
dart_repl_sandbox >=0.11.1 <0.12.0 0.11.1
meta >=1.0.4 <2.0.0 1.1.2
package_resolver >=1.0.2 <2.0.0 1.0.2
pub_cache >=0.1.0 <0.2.0 0.1.1
vm_service_client 0.2.4
Transitive dependencies
async 1.13.3 2.0.4
charcode 1.1.1
cli_util 0.0.1+2 0.1.2+1
collection 1.14.5
convert 2.0.1
crypto 2.0.2+1
csslib 0.14.1
glob 1.1.5
html 0.13.2+2
http 0.11.3+16
http_parser 3.1.1
isolate 1.1.0
json_rpc_2 2.0.7
logging 0.11.3+1
package_config 1.0.3
path 1.5.1
plugin 0.2.0+2
pub_semver 1.3.2
source_span 1.4.0
stack_trace 1.9.2
stream_channel 1.6.3
string_scanner 1.0.2
typed_data 1.1.5
utf 0.9.0+4
watcher 0.9.7+7
web_socket_channel 1.0.6 1.0.7
when 0.2.0
which 0.1.3
yaml 2.1.13
Dev dependencies
test >=0.12.0 <0.13.0