Targets · Dart · Example

Example

The whole language in one short program — a module with a record, a tagged union, a function with per-platform native bodies, and a function that wires up state, a write-back and a return — and the complete Dart it renders to. It is the same program shown on the language page.

Contents

How a Program becomes Dart, in parts. Start with the introduction, then follow each part into the rendered output and the runtime it links against.

Every keyword, in one program

Each keyword has its own page under keywords; here they are all together.

MODULE App

  TYPE Profile
    FIELD Text name
    FIELD Maths.Integer age

  TYPE Status
    OPTION App.Profile active
    OPTION Text pending

  FUNCTION Text Greet
    INPUT Text name
    NATIVE js    "return 'Hi ' + name;"
    NATIVE dart  "return 'Hi ' + name;"
    NATIVE swift "return \"Hi \" + name"

  FUNCTION Text Welcome
    INPUT BINDING App.Profile profile
    HOLE Text row
      INPUT Text line
    STATE Maths.Integer count = 0
    STATE LOCKED Network.Web.Response saved = null
    REVERSE App.Profile submit
      LET Network.Web.Response response = Network.Web.Client.Post profile
      SET saved = response
    LET Text label = Maths.Integer.ToString count
    = label

Rendered Dart

The record and union become final classes named by the underscore join; the module's functions are statics on a class; state carries an explicit type; the function's dart body is spliced in; and the trailing = becomes a return.

final class App_Profile {
  final String name;
  final int age;
  App_Profile(this.name, this.age);
}

sealed class App_Status {}
final class App_Status_active extends App_Status { final App_Profile value; App_Status_active(this.value); }
final class App_Status_pending extends App_Status { final String value; App_Status_pending(this.value); }

class App {
  static String Greet(String name) {
    return 'Hi ' + name;                 // the dart NATIVE body
  }

  static ReactiveValue<String> Welcome(App_Profile profile, String Function(String line) row) {
    final count = Program._Runtime.Reactive.State<int>(0);
    final saved = Program._Runtime.Reactive.StateLocked<Network_Web_Response>(null);
    Program._Runtime.Reactive.Reverse(submit, () {
      final response = Network_Web_Client.Post(profile);
      Program._Runtime.Reactive.Set(saved, response);     // SET
    });
    final label = Maths_Integer.ToString(count);
    return label;
  }
}

Reading it

Indentation becomes nested closures — the REVERSE body is a trailing () { … }. Dotted names are joined with an underscore, keeping the final access a real dot (Maths_Integer.ToString) — see naming considerations. The per-keyword mapping is on keywords.