a muffin with purple glowing regions where a 3d vornoi function using chebychev distance exceeds some threshold

metamuffin's personal website


Some Thoughts on Programming Language Design

This is a collection of ideas to look at when inventing new langauges.

Other Ideas

Type System

# Haskell
data LinkedList a = Nil | Cons a (Box (LinkedList a))
data Test = Empty | Blub Int | State { x :: Int, y :: Int }
# Rust
enum LinkedList<T> { Nil, Cons(T, LinkedList<T>) }

Memory Management

Compile-time logic

fn format(template: String, args: [String]) -> String {
    template.replace("@", (match, i) => args[i])
}

fun add(x, y) x + y

fun main() print(format!("@ ist @; @", ["1+1", 1+1, x]))
# should expand to
fun main() print("1+1 ist 2; " ~ x))

Examples

Fizz-Buzz

for (n in 0..100) {
    if (n % (3*5) == 0) print("FizzBuzz")
    else if (n % 3 == 0) print("Fizz")
    else if (n % 5 == 0) print("Buzz")
    else print(n)
}


if (true) x = 1
if (true) { x = 1 }
f(x) = 10 + g(x)
f x = 10 + g x

main = {

}

Article written by metamuffin, text licenced under CC BY-ND 4.0, non-trivial code blocks under GPL-3.0-only except where indicated otherwise



Advertisement by a first-party
Advertisement by a third-party