Skip to content

dev@lang

Olivier DALET edited this page Feb 22, 2021 · 11 revisions

Languages

Misc information

Oracle GraalVM

Eric Lippert

Mikhail Barash

https://medium.com/@mikhail.barash.mikbar

Lesser-known languages worth looking at

Microsoft Researh

  • Ruby-like, statically type checked, built-in type inference
  • C-bindings
  • Null representation: union between the type and nil

Example:

if rand(2) > 0
  my_string = "hello world"
end

puts my_string.upcase

gives:

$ crystal hello_world.cr
Error in hello_world.cr:5: undefined method 'upcase' for Nil (compile-time type is (String | Nil))

puts my_string.upcase
  • Python-like
  • Inspiration from Ada and modula
  • Modern type system with local type inference, tuples, generics and sum types.
  • Nim's memory management is deterministic and customizable with destructors and move semantics, inspired by C++ and Rust.
import strformat

type
  Person = object
    name: string
    age: Natural # Ensures the age is positive

let people = [
  Person(name: "John", age: 45),
  Person(name: "Kate", age: 30)
]

for person in people:
  # Type-safe string interpolation,
  # evaluated at compile time.
  echo(fmt"{person.name} is {person.age} years old")
const std = @import("std");
const json = std.json;
const payload =
    \\{
    \\    "vals": {
    \\        "testing": 1,
    \\        "production": 42
    \\    },
    \\    "uptime": 9999
    \\}
;
const Config = struct {
    vals: struct { testing: u8, production: u8 },
    uptime: u64,
};
const config = x: {
    var stream = json.TokenStream.init(payload);
    const res = json.parse(Config, &stream, .{});
    // Assert no error can occur since we are
    // parsing this JSON at comptime!
    break :x res catch unreachable;
};
pub fn main() !void {
    if (config.vals.production > 50) {
        @compileError("only up to 50 supported");
    }
    std.log.info("up={d}", .{config.uptime});
}
Clone this wiki locally