ClojureDart Cheatsheet
ClojureDart Cheatsheet
:keys, :strs and :syms are proud to introduce :flds Sometimes interop requires implementing a function
Cheatsheet for Clojurists
their object-destructuring counterpart.
or method taking Dart optional parameters.
CLI (let [{:flds [height width]} size] …) is [a b c .d .e] 3 positional parameters and two
clj -M:cljd init equivalent to:
named ones: d and e.
clj -M:cljd flutter # press RET to restart (let [height (.-height size) [a b c ... d e] 5 positional parameters, 3 xed
clj -M:cljd compile width (.-width size)] and 2 optional.
clj -M:cljd clean # when in panic …) [.a 42 .e] two named parameters a and b where a
clj -M:cljd upgrade # stay current w/ CLJD
defaults to 42.
Constructors
Using Dart packages In Dart, constructors do not always allocate, they can [... a 42 b] 2 optional positional parameters a and
In the ns form, :require as usual but with a string return existing instances. That’s why there’s no new b where a defaults to 42.
instead of a symbol:
nor trailing . (dot) in ClojureDart.
Enums
(ns my.project Default constructors are called with classes in
(:require
Enums values are just static properties on types.
function position.
(StringBuffer "hello")
Types and aliases Named constructors are called like static methods.
Consts and const opt-out
Unlike Clojure/JVM, types can be pre xed by an (List/empty .growable true) Dart has consts: deduplicated compile-time constant
alias. m/ElevatedButton refers to ElevatedButton in expressions in which const constructors may
Understanding Dart signatures participate. It’s an opt-in mechanism.
instance.
Property access
Instance get (.-prop obj), set (.-prop! obj x) or
Named arguments Creating classes: operators
(set! (.-prop obj) x)
Some Dart functions and methods expect named Dart supports operators overloading but not all
arguments (argname: 42 in Dart), in ClojureDart operators make valid Clojure symbol ([]= for
Static m/Colors.purple, this can even be chained m/
it’s .argname 42.
example). That’s why it’s valid ClojureDart to have
Colors.purple.shade900 or even terminated with a
(m/Text "Hello world" strings as methods names.
method call
.maxLines 2 (. list "[]=" i 42) ; list[i] = 42
(m/Colors.purple.shade900.withAlpha 128).
.softWrap true It’s also valid to use strings-as-names when
.overflow m/TextOverflow.fade) implementing operator overloads as part of a class
de nition.
fi
fi
fi
fi
expects one parameters [this] while a setter (m/Center .child (m/Text "hello"))
Dependencies can be any watchable including other
expects two [this v].
When the two expressions are separated by a dotted
cells. Dependencies are read using f/<! (“take”). f/
If the property is de ned in a parent class or interface, symbol, this symbol is used to thread them:
[“package:flutter/material.dart” :as m]
:watch takes a bindings vector. Unlike :let, :get [m/Navigator] retrieves instance returned by
f/run [& widget-body] expressions must be watchable and binding forms (m/Navigator.of context)
Called from main, starts the application (a Widget). Its will be successively bound to values produced by
their watchable.
:context directive
body is interpreted as per f/widget. Makes the root For when Flutter asks for more context.
of the app reload-friendly.
:watch [v an-atom]
(m/Text (str v)) :context ctx binds ctx to a BuildContext instance.
f/widget [& widget-body] When an-atom changes, everything after :watch will
:vsync directive
Mother of all macros. Evaluates to a Widget.
update with v bound to the current value of an-atom.
fi
fi
fi
fi
fi