MiniLang

nicup14

NICU PETRI

Posted on August 8, 2024

MiniLang

Github link

A type-safe C successor that compiles directly to various platforms.

Motivation

The language is designed to closely match c features along with some zero-overhead quality of life improvements that you would find in a modern language, while maintaining the ease of learning the language (in about 10 minutes or less via QUICKSTART.md). Moreover, the type system is stricter than c, which prevents common bugs (flaws) of the c language. Memory safety is also a primary concern. As for c compatibility, the language is bidirectionally compatible with c (c can be used in ML, ML can be used in c).

Language-specific features

  • Builtins
  • Booleans
  • References
  • Fixed-length integers
  • Fixed-length pointers
  • Type inference
  • Heredocs
  • Aliases
  • Defers
  • Imports
  • Namespaces
  • Hygienic macros
  • Function overloading
  • Uniform function call syntax (UFCS)
  • Multi-line statements

Features

  • Modern
  • Compiled
  • Strongly typed
  • Function overloading
  • Hygienic macro system
  • C bidirectional compatibility
  • Uniform function call syntax (UFCS)
  • Easy to learn and use
  • Flat learning curve

Samples

Hello World

# From samples/helloworld/src/main.ml:
import "stdlib/print"

fun main: int32
    print "Hello World!"
    ret 0
end
Enter fullscreen mode Exit fullscreen mode

String (UFCS)

# From samples/str-ufcs/src/main.ml:
import "stdlib/print"
import "stdlib/string"

fun main: int32
    # Is equivalent to:
    # print(concat(str("Hello "), str("World!")))
    (str("Hello ").
        concat(str("World!")).
        print)
end
Enter fullscreen mode Exit fullscreen mode

FizzBuzz

# From samples/fizzbuzz/src/main.ml:
import "stdlib/print"

fun fizz_buzz(num: int64): void
    let idx = 1

    while idx <= num
        if idx % 15 == 0
            println(idx, ": FizzBuzz")
        elif idx % 3 == 0
            println(idx, ": Fizzz")
        elif idx % 5 == 0
            println(idx, ": Buzz")
        end

        idx = idx + 1
    end
end

fun main(): int64
    fizz_buzz(15)
    ret 0
end
Enter fullscreen mode Exit fullscreen mode
๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
nicup14
NICU PETRI

Posted on August 8, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

ยฉ TheLazy.dev

About