Skip to content

v0.8.0

Choose a tag to compare

@github-actions github-actions released this 08 May 04:55
· 122 commits to main since this release

Language

match expression: pattern match on literals, ranges, and multiple values per arm; use _ as a wildcard and if guards for conditional arms:

grade = match score {
  90..100      => { "A" }
  80..89       => { "B" }
  "Sat", "Sun" => { "Weekend" }
  n if n > 50  => { "Pass" }
  _            => { "Fail" }
}

Structural interfaces: declare an interface with required method signatures; any class implementing those methods satisfies the interface, no explicit declaration needed:

interface Drawable {
  def draw -> String
}

class Badge {
  def draw -> String {
    "drawing badge"
  }
}

def render(item: Drawable) -> String {
  item.draw
}
render(Badge.new)

Abstract classes: mark a class abstract to prevent direct instantiation; use abstract def to require subclasses to implement a method:

abstract class Shape {
  def area -> Float
}

class Square < Shape {
  attr length: Float 

  abstract def area -> Float {
    self.length * self.length
  }
}

print Square.new(length: 4.0).area 

Modules and mixins: define reusable method groups with module and mix them into classes with include:

module Greetable {
  def greet -> String {
    "hello from " + self.name
  }
}

class Person {
  include(Greetable)
  def name -> String { "Alice" }
}

Person.new.greet
# "hello from Alice"
  • super now works Ruby-style — bare super forwards all arguments; super(args) passes explicit arguments; super.method is no longer valid

Error messages

  • Runtime errors now include source context and column position
  • No-method errors show the value's type: 30 (Int) has no method 'push'
  • Typos in method names now show a did-you-mean suggestion
  • Parse errors at or past end of file now show source context

REPL

  • quit and exit commands now work in sapphire console