Skip to content

Latest commit

 

History

History
90 lines (62 loc) · 3.01 KB

quick-start.md

File metadata and controls

90 lines (62 loc) · 3.01 KB

ClojureDart Quick Start

This document is about creating a CLI app written in Dart; for a mobile app follow our Flutter Quick Start. However it's recommended to first give a try to the current document.

System requirements

ClojureDart needs at least Java 9.

If you already have Dart installed, make sure your version of the sdk is at least 2.12 -- this version introduced a big change (types are not nullable by default) to the language, use dart --version to check. Code produced by ClojureDart wouldn't be compatible with previous versions of Dart.

If you already have the clj command installed make sure to upgrade to at least the 1.10.3.814. This release allows to easily use private git deps.

3. Create a new project

First, create a Clojure project, you need to specify it's a pure Dart (not Flutter) project and where is the main function (here quickstart.helloworld):

mkdir helloworld
cd helloworld
cat << EOF > deps.edn
{:paths ["src"] ; where your cljd files will live
 :deps {org.clojure/clojure {:mvn/version "1.10.1"}
        tensegritics/clojuredart
        {:git/url "[email protected]:tensegritics/ClojureDart.git"
         ; or  "https://github.com/tensegritics/ClojureDart.git"
         :sha "7b6b417a0feb83dd3070d5171f70b251bcbea7d6"}}
 :aliases {:cljd {:main-opts ["-m" "cljd.build"]}}
 :cljd/opts {:kind :dart
             :main quickstart.helloworld}}
EOF

Then, you need to prepare this project to also be a Dart project:

clj -M:cljd init

And add the main namespace:

mkdir -p src/quickstart
cat << EOF > src/quickstart/helloworld.cljd
(ns quickstart.helloworld)

(defn main []
  (print "hello, world\n"))
EOF

The src directory isn't special, you are free to layout your project as you like, as long as you don't interfere with Dart's project layout (bin and lib especially).

4. Compiles to Dart

By default compilation starts from the main namespace (here quickstart.helloworld) and transitively compiles dependencies.

clj -M:cljd compile

The above command compiles the project only once and exits. When you are actively working on a piece of code we recommend you use watch instead of compile:

clj -M:cljd watch

5. Run your program

Compiled Dart files are found under lib/cljd-out; to execute the program, just type:

dart run

By doing so you have run your program on the Dart VM. To get an actual executable, enter:

dart compile exe -o helloworld bin/helloworld.dart

Without the -o helloworld option it would have created a helloworld.exe alongside helloworld.dart.

6. Enjoy!

Write more clojure code, new namespaces, have fun. The watcher will pick up your changes. Then execute your dart file again.