slate 0.0.34 — class properties, symbol-named operators, return-type inference
Classes gain properties and operators named for the symbol they overload, the checker learns to
read a function's answer off its own body, and eighteen builtins arrive together.
Class properties: get and set
A class body can declare a computed property instead of a plain field:
class Rect
var w
var h
get area(self) = self.w * self.h
get width(self) = self.w
set width(self, v)
self.w = v
r.area and r.width call the getter; r.width = 12 calls the setter. async get/async set are
refused at the point of declaration — a property read has no way to be awaited by its caller.
Operators are methods named for the symbol — BREAKING
A class overloads + - * / % == < <= > >= <=> and unary - by naming a method after the operator
itself, not by a word:
class Money
var cents
+(self, o) = Money(self.cents + o.cents)
unary_-(self) = Money(-self.cents)
<=>(self, o) = self.cents - o.cents
The word-shaped hooks this replaces — plus, equals, and the rest — are gone. Any class that
overloaded an operator through one of the old names stops being called for it; rename the method to
its symbol.
Return-type inference, and if/match typed by their value
A function's answer is inferred from its body rather than needing an annotation, and an if or
match used for its value is typed from what its branches actually produce. Type narrowing follows a
test down the branch it holds on:
widen(x: string | number) = if x is string then len(x) else x * 2
x is string in the then branch and number in the else, so both calls type-check.
Eighteen new builtins, and cookies on slate:dom
- Promise combinators:
all,allSettled,race,any. - Strings:
padStart,padEnd,replaceAll,includes. - Collections:
groupBy,zip,unique,chunk,count,partition,minBy,maxBy. - Numbers:
toFixed,formatNumber. slate:dom:cookies(),cookie(name),setCookie,deleteCookie.
Alongside these: the JavaScript back end refuses await outside an async function at compile time
rather than at run time; imageShape reads any PNG header rather than a fixed subset; ESM resolution
finds node's own built-in modules; and browser fetch resolves a relative URL against the page rather
than refusing it.
0.0.32's path-traversal-safe files() and 0.0.33's test-hook event-loop fix are already out and
unchanged here.
Installing
brew update
brew upgrade slate
The formula names the same nine Homebrew libraries the last release did.
The compiler floor is sysl 0.0.105.