Skip to main content Svelte Highlight v7.21.1

Odin language preview

1. Procedures and structs

proc declarations, types, and directives
horizon-dark
package main

import "core:fmt"

Vector2 :: struct {
	x, y: f32,
}

length :: proc(v: Vector2) -> f32 {
	return v.x * v.x + v.y * v.y
}

main :: proc() {
	v := Vector2{3, 4}
	fmt.println("length:", length(v))
}
atom-one-dark
package main

import "core:fmt"

Vector2 :: struct {
	x, y: f32,
}

length :: proc(v: Vector2) -> f32 {
	return v.x * v.x + v.y * v.y
}

main :: proc() {
	v := Vector2{3, 4}
	fmt.println("length:", length(v))
}
github-dark
package main

import "core:fmt"

Vector2 :: struct {
	x, y: f32,
}

length :: proc(v: Vector2) -> f32 {
	return v.x * v.x + v.y * v.y
}

main :: proc() {
	v := Vector2{3, 4}
	fmt.println("length:", length(v))
}
dracula
package main

import "core:fmt"

Vector2 :: struct {
	x, y: f32,
}

length :: proc(v: Vector2) -> f32 {
	return v.x * v.x + v.y * v.y
}

main :: proc() {
	v := Vector2{3, 4}
	fmt.println("length:", length(v))
}
nord
package main

import "core:fmt"

Vector2 :: struct {
	x, y: f32,
}

length :: proc(v: Vector2) -> f32 {
	return v.x * v.x + v.y * v.y
}

main :: proc() {
	v := Vector2{3, 4}
	fmt.println("length:", length(v))
}
github
package main

import "core:fmt"

Vector2 :: struct {
	x, y: f32,
}

length :: proc(v: Vector2) -> f32 {
	return v.x * v.x + v.y * v.y
}

main :: proc() {
	v := Vector2{3, 4}
	fmt.println("length:", length(v))
}

2. Enums and switches

enums, #partial switch, and literals
horizon-dark
Direction :: enum {
	North,
	East,
	South,
	West,
}

describe :: proc(d: Direction) -> string {
	#partial switch d {
	case .North: return "up"
	case .South: return "down"
	case: return "sideways"
	}
}
atom-one-dark
Direction :: enum {
	North,
	East,
	South,
	West,
}

describe :: proc(d: Direction) -> string {
	#partial switch d {
	case .North: return "up"
	case .South: return "down"
	case: return "sideways"
	}
}
github-dark
Direction :: enum {
	North,
	East,
	South,
	West,
}

describe :: proc(d: Direction) -> string {
	#partial switch d {
	case .North: return "up"
	case .South: return "down"
	case: return "sideways"
	}
}
dracula
Direction :: enum {
	North,
	East,
	South,
	West,
}

describe :: proc(d: Direction) -> string {
	#partial switch d {
	case .North: return "up"
	case .South: return "down"
	case: return "sideways"
	}
}
nord
Direction :: enum {
	North,
	East,
	South,
	West,
}

describe :: proc(d: Direction) -> string {
	#partial switch d {
	case .North: return "up"
	case .South: return "down"
	case: return "sideways"
	}
}
github
Direction :: enum {
	North,
	East,
	South,
	West,
}

describe :: proc(d: Direction) -> string {
	#partial switch d {
	case .North: return "up"
	case .South: return "down"
	case: return "sideways"
	}
}