跳到主要内容

Introduction

WARNING: Atem is highly experimental.

Atem is a general purpose programming language. Atem takes inspiration from many other languages like C++, Cpp2, Circle, Carbon, Rust, Swift, D, Zig, Scala, Kotlin, Go, Haskell, and Julia.

Design Goals and Principles

Design Goals (in no particular order):

  • Performant
  • Scalable
  • Robust
  • Extensible and Customizable
  • Expressive
  • Consistent
  • Opt-in Safety

Design Principles (in no particular order):

  • Prefer runtime exceptions over runtime crashes
  • Prefer compile time error over runtime exceptions
  • Prefer explicitness over implicitness to make the code self-explanatory and intent clear
  • Prefer implementing language features in one consistent syntax to avoid additional burdens on users
  • Prefer expressions over statements to encourage the use of functional programming.

Atem Standard Library

Atem has its own standard library which contains commonly used algorithms, data structures, and many other tools to help you build programs on Atem. The atem-stdlib also has its own documentation, see here(WIP).

Language Tour

Hello World

println := import func std.io.print.println

main := func {
println("Hello World!")
}

Fibonacci

println := import func std.io.print.println

fib := func (n: UInt64) -> Int64 recursive throws pure
require {
expect n > 0
ensure with ret := return ret >= 0
}
if n == 1 or n == 2 then 1 else self(n - 1) + self(n - 2)

_ := test "recursive fibonacci" {
println("${fib(10)}") //print 55
}

Fibonacci (non-recursive)

println := import func std.io.print.println

fib := func (n: UInt64) -> UInt64 throws pure
require {
expect n > 0
ensure with ret := return ret >= 0
}
{
if n == 1 or n == 2 {
return 1
} else {
f1 := var 1 as Int64
f2 := var 1 as Int64
f3 := var -1 as Int64
for i in 3...n {
f3 = f1 + f2
f1 = f2
f2 = f3
}
return f3
}
unreachable
}

_ = test "non-recursive fibonacci" {
println("${fib(10)}") //print 55
}

Printable Points

Printable := protocol member {
require print := func () -> () throws default = {
println("{}", self)
}
}

Point := struct member {
public x := var 0 as Int8
public y := var 0 as Int8
}

PrintablePoint := class extend {
inherit Point
impl Printable with {
require print := func () -> () throws {
println("(${self.x}, ${self.y})")
}
}
} init {
:= (x: Int8, y: Int8) {
self.x = x
self.y = y
}
:= (coord: Int8) {
self.init(coord, coord)
}
} deinit {
:= {
println("Point (${self.x}, ${self.y}) is deinitializing")
}
} member {
public isAtOrigin := func () -> bool
if self.x == 0 and self.y == 0 then true else false
}

_ := test "Printable Point" {
point := val PrintablePoint.init(1, 2)
point.print() //print (1, 2)
println("${point.isAtOrigin()}") //print false
}

Rectangle with Calculated Properties

Point := class member {
public x := var 0.0
public y := var 0.0
}
Size := class member {
public width := var 0.0
public height := var 0.0
}
Rectangle := class member {
public origin := var Point.init()
public size := var Size.init()
public center := var Point.init() with {
:= get {
centerX := val self.origin.x + (self.size.width / 2)
centerY := val self.origin.y + (self.size.height / 2)
return Point.init(x = centerX, y = centerY)
}
:= set(newCenter) {
self.origin.x = self.newCenter.x - (self.size.width / 2)
self.origin.y = self.newCenter.y - (self.size.height / 2)
}
}
}

Allocating Memory

_ := test "Allocating Memory" {
println := import func std.io.print.println
GeneralPurposeAllocator := import class std.memory.allocator.GeneralPurposeAllocator;

gpa := var GeneralPurposeAllocator.init()
defer { gpa.deallocateAll() }
allocator := var gpa.getAllocator()

buffer := var try! allocator.allocate(size = 64)
println("Get a buffer: ${buffer.getRawPointer()}")

return 0
}