Crates.io | rual |
lib.rs | rual |
version | 0.0.2 |
source | src |
created_at | 2020-02-28 16:59:58.371353 |
updated_at | 2020-03-18 17:44:02.374081 |
description | A slim, embeddable language |
homepage | |
repository | https://gitlab.com/IovoslavIovchev/rual |
max_upload_size | |
id | 213594 |
size | 37,203 |
A small, functional-first, embeddable language for Rust, inpired by Lua.
-- this is a single-line comment..
-{
this is
a multiline comment
}-
-- a flat lambda
f: x, y -> x + y
-- or with a block
g: x, y -> {
let z = 5
x + y + z
}
let x = 3
let b = true
let s = 'string'
-- a tuple
let (p, q) = (1, 7)
-- a list of `i32`
let xs = [ 1..10 ]
-- this `xs` shadows the previous definition
let [x, ...xs] = map(xs, \x -> 11 - x) -- x = 10, xs = [ 9..1 ]
-- a map with `Num` keys and `String` values
let m = { 1: '0x01', 0: '0x00' }
Not all of the syntax is currently supported
let num = 73
let [t, f] = [true, false]
let (x, y) = (21, 'fhtagn')
-- the good ol' `if-else`
if condition {
-- ..
}
else {
-- ..
}
-- ..or a slightly different version
-- this is equivalent to a chain of `if/else if/else` statements
if {
| condition1 -> routine1(),
| condition2 && condition3 -> routine2(),
| _ -> fallback(), -- a fallthrough is necessary
}
-- ..or standard pattern matching
let lvl = match tup {
| (1, 8) -> 1,
| (x, y) when x % y == 0 -> 2,
| _ -> 3
}
-- parameters are listed after `:`, separated by `,`
factorial: x -> {
if {
| x < 2 -> 1,
| _ -> factorial(x - 1)
}
}
sum: x, y -> {
let z = x + y
-- functions return the last expression in their block
z
}
-- functions without parameters can be written with an explicit `: ()`, such as
one: () -> {
let x = 1 -- assignment has type of `()`
}
-- ..or without it
two {
let x = 2
}
-- ..and are ivoked as
one()
two()