Getting started
Prerequisites
Section titled “Prerequisites”- .NET 10 SDK
- Git
Install the compiler
Section titled “Install the compiler”There are no packaged releases yet, so build am from source:
git clone https://github.com/itisrazza/amethyst.gitcd amethystdotnet buildThen make the am command available by adding an alias to your shell profile, pointing
at your clone:
alias am='dotnet run --no-build --project ~/amethyst/src/Amethyst.Compiler.Cli --'Hello, world
Section titled “Hello, world”Tradition demands it, and who are we to argue with tradition. Programs start at a
top-level main method. Create hello.am:
def main: Void puts "Hello, world!"endCompile and run it in one step:
am run hello.amHello, world!A first class
Section titled “A first class”class Greeter property name: String
def initialize(name: String): Void @name = name end
def greet: Void puts "Hi, #{name}!" endend
def main: Void Greeter.new("Ada").greetendproperty name: Stringdeclares the@nameinstance variable with a getter and a setter. See Classes.initializeis the constructor, called byGreeter.new."Hi, #{name}!"interpolates; inside the class,namereads the property.- Parentheses are optional when a method takes no arguments.
am run greeter.amHi, Ada!Check without running
Section titled “Check without running”am check lexes, parses and type-checks a file without compiling it. It’s a
pessimist, so that production can be an optimist:
def main: Void var count: Int = "three"endam check oops.amoops.am:2:3: error [AM3002] Type mismatch: expected 'Int', got 'String'Diagnostic codes tell you which stage reported the problem:
| Codes | Stage |
|---|---|
AM1xxx |
Lexer |
AM2xxx |
Parser |
AM3xxx |
Type checker |
AM4xxx |
Code generation |
Build an executable
Section titled “Build an executable”am build compiles to a .NET assembly next to the source file, along with the
runtimeconfig.json that dotnet needs to run it:
am build hello.am # writes hello.dllam build hello.am -o app.dll # or choose the output pathdotnet hello.dllCongratulations: you’ve written .NET without opening Visual Studio. Treat yourself.
Next steps
Section titled “Next steps”- Read the language overview for the design goals and ethos.
- Coming from another language? There are guides for C#, F#, Visual Basic, Java, Kotlin, Python, Ruby and Crystal developers.
- Type-safe builders shows how to write Ruby-style DSLs the compiler can check.
- Amethyst on the Rocks is the web framework, if you’re feeling thirsty.
- Types, Methods and Blocks and Closures cover the everyday parts of the language.
- The API reference documents the libraries every Amethyst program can use.