Skip to content

Amethyst Language Specification

Amethyst is a Ruby-inspired, statically typed language that compiles to .NET IL. Someone familiar with Ruby should be able to pick it up with minimal friction.

  • Ruby-inspired syntax (def/end, do/end blocks, string interpolation, symbols)
  • Static typing with inference — annotate where it matters, not everywhere
  • Non-nullable by default, with opt-out per file or project for C# interop
  • Compile to .NET IL with full bidirectional C# interop
  • Useful, actionable compiler error messages
  • Limited duck typing via structural typing
  • Metaprogramming support, bounded to what works with a static type system
  • DSL-building capability (Kotlin-style typed receivers in blocks)
  • Code should be fun and expressive to write
  • A Ruby runtime or full Ruby compatibility
  • Unrestricted dynamic dispatch at runtime
  • Scripting-only use — Amethyst is intended for full projects

Amethyst borrows Ruby’s commitment to developer happiness. Code should read naturally and reward the writer. The following features are preserved from Ruby with this in mind:

  • Optional parentheses — puts "hello" is valid alongside puts("hello")
  • Everything is an expression — if/else, case/when, blocks all return values
  • Postfix conditionals — return if invalid?, log message unless quiet?
  • ? and ! method naming — valid?, save! are idiomatic
  • Fluent chaining — APIs are designed to chain naturally
  • Enumerable builtins — map, select, reduce, any?, all? etc. are built in
  • Truthiness — only nil and false are falsy. Conditions must be Bool or nullable; if "hello" is a compile error
  • String interpolation — "Hello, #{name}!"
  • Symbols — :role, :name as lightweight identifiers
  • Destructuring — a, b = [1, 2], first, *rest = array

Amethyst method names are mangled for .NET consumers, following .NET’s own naming habits where one exists.

name? methods return Bool unless annotated otherwise. The compiled name depends on the return type:

Return type Compiled name Example
Bool IsName valid? → IsValid
T? NameOrDefault first? → FirstOrDefault
Anything else NameQuestion size? → SizeQuestion

For Bool returns, names that already start with has, can, should, will, must or needs keep that prefix instead of gaining Is: has_error? compiles as HasError.

! marks one of two things: a method that raises instead of returning nil or false, or a method that changes its receiver in place instead of returning a new value. A name! with no matching name compiles as Name. When both exist, the compiler picks the names from their return types, checking these rules in order:

Pair Rule Compiled names
Raises name returns T? or Bool, and name! returns T or Void name → TryName, name! → Name
In place name! returns Void name → Name, name! → NameInPlace
Neither — name → Name, name! → NameBang
def find(id: Int): User? # TryFind
def find!(id: Int): User # Find
def sort: Array[T] # Sort
def sort!: Void # SortInPlace

In-place ! methods return Void, unlike Ruby’s, which return nil when nothing changed.

A protocol compiles to a .NET interface, and its name gains the I prefix that .NET interfaces use:

Amethyst .NET
protocol Shape interface IShape
protocol Drawable[T] interface IDrawable<T>

Going the other way, a .NET interface’s name loses its I in Amethyst, so System.IDisposable is Disposable. The original name works too: IDisposable and Disposable are the same type.

When both names exist, such as in a .NET namespace with a Shape class and an IShape interface, the exact name wins: Shape is the class and IShape is the interface. After implements, which only accepts protocols, Shape still means IShape:

class Square
implements Shape # IShape, since the Shape class can't be implemented
end

Interfaces whose names don’t start with I and a capital letter keep their exact name.

@[Alias("...")] overrides any generated name.

This specification is a work in progress. Sections marked [TBD] are not yet decided.