Share your Programming Language Jam submissions here!

← Back to all posts
Sardonyx Programming Language
h
sugarfi (587)

Sardonyx

This is the Sardonyx programming language, developed by team @SardonyxLang, which is comprised of me, @sugarfi, and @Zavexeon. Sardonyx is a small, bytecode-interpreted programming language, designed to be simple, concise, and elegant. Syntax-wise, it is similar to Rust, Python, and Lua.

Introduction

Sardonyx is a small OOP language. While lightweight, it is still feature-rich. It is interpreted through a bytecode VM, and written in Ruby. It was originally going to be in Crystal, but it turns out Crystal's typing is actually pretty bad. Sardonyx is available as a Ruby gem, so you can install it locally using:

gem install sardonyx

It also has an associated package manager, Volcano, which you can read about here. You can also install that using Rubygems:

gem install volcano

Quick Tour

I'll go through the language pretty quickly here; for more info, see the docs below.

Use # for single line comments and #> <# for multiline:

# comment
#> comment <#

Variables are assigned with =:

a = 5
b = 6

Math works as normal. For example:

a = a + 1
b * 2

If statements are done with if:

if a == b {
    c()
} else if b == d {
    e()
} else {
    f()
}

We can also pass a single expression to evaluate as a result:

if a == b 5 else 6

Loops are done with while and for:

while i < 5 {
    i = i + 1
}

for i in x {
    j = i
}

Functions are declared using fn:

fn factorial(n) {
    if n == 1 1 else n * f(n - 1)
}

Objects function as both classes and namespaces. To declare a namespace object, we use object:

object Namespace {
    a = 5
}

Namespace:a # 5

By adding parameters to the object declaration, we make it class-like:

object MyClass(a, b) {
    fn method(n) { a + b + n }
}

We can use new to instantiate an object:

obj = new MyClass(5, 6)
obj.method(7)

Resources

  • Hopefully that little tour above piqued your interest. If you want to fully learn Sardonyx, check out the documentation here.
  • Sardonyx can be found on Github here. Here you will find the standard library and package manager.
  • The source code can be found on the Github above or on this repl.
  • Want to just try out Sardonyx quickly? See here

Closing

Once again, Sardonyx was developed my me and Zavexeon. I hope you enjoyed learning a bit about and check out some of the links above! Note that Sardonyx is still in alpha; if you find any bugs, report them in the comments and we will try to patch them as soon as possible. Feel free to open issues and pull requests on Github as well. Thanks for reading, and enjoy Sardonyx!