Skip to content

Miscellaneous features and fixes to implement #312

@LPTK

Description

@LPTK

Syntax

  • Special-case {} to mean an empty object (currently, one has to use new Object)
  • Parsing this currently fails:
    foo(1,
      2)

Mutability/Immutability

  • Make arrays and object literals immutable by default (using Object.freeze)
  • Allow mut modifier on array and object literals
    This will remove the {} footgun (it resolves to runtime.Unit, which is currently not frozen!). For a fresh mutable records, users will need to write mut {}.
  • Make class ctors use Object.freeze by default – this will probably require generating getters/setters for mut vals

Bugs

  • Currently, && and || are not short-cirtuiting!

Code-gen improvements

  • Should avoid generating very repetitive "else throw match error" structures

    Example
    data class Foo(a)
    
    :sjs
    case Foo(Foo(Foo(x))) then x
    //│ JS (unsanitized):
    //│ let lambda;
    //│ lambda = (undefined, function (caseScrut) {
    //│   let param0, param01, param02, x;
    //│   if (caseScrut instanceof Foo1.class) {
    //│     param0 = caseScrut.a;
    //│     if (param0 instanceof Foo1.class) {
    //│       param01 = param0.a;
    //│       if (param01 instanceof Foo1.class) {
    //│         param02 = param01.a;
    //│         x = param02;
    //│         return x
    //│       } else {
    //│         throw new globalThis.Error("match error");
    //│       }
    //│     } else {
    //│       throw new globalThis.Error("match error");
    //│     }
    //│   } else {
    //│     throw new globalThis.Error("match error");
    //│   }
    //│ });
    //│ lambda
    //│ = [function]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions