ClojureDart icon indicating copy to clipboard operation
ClojureDart copied to clipboard

platform conditionals

Open cgrand opened this issue 1 year ago • 3 comments

Dart has conditional importing to deal with web vs native.

Clojure has conditional readers.

How do we expose Dart affordances and can we do it with conditional reading?

cgrand avatar Nov 16 '23 15:11 cgrand

We can't use conditional reading because conditional reading will only pick one feature (out of web and native) while we must compile both to a single codebase.

Then it's going to be a special form.

(dart/sniff
  dart:io (some native code)
  dart:html (some web code))

could we lift these expressions to distinct files and emit conditional imports automatically?

We should also modify ns to allow to specify :when in a require.

cgrand avatar Nov 16 '23 16:11 cgrand

See #128

cgrand avatar Nov 16 '23 17:11 cgrand

Let's ponder about

(dart/sniff
  dart:io (some native code)
  dart:html (some web code))

My original idea was to have it replaced by some function call and the function being defined in a conditionally imported lib. However this approach is going to create weird cases when for example you have an await or a recur inside the expressions (because then they would apply to the extracted function).

My new idea is to have a new special in "dart sexp" (our representation of the subset of dart code we produce) too. Then we would just walk the top-level code in search of a dart/platform-case and if found we would produce dart/platform-case-free variants that we would dump in conditionally imported helper libs.

cgrand avatar Nov 16 '23 23:11 cgrand