Link (.lk) is a systems language currently in early development. It is dynamically typed and prototype-based today, with class-based OOP and static typing planned. The current implementation is a tree-walking interpreter written in C, with a compiler as the next milestone.
Requires CMake and Ninja.
make # configure + build
make test # run tests
make stdlib # build standard library modulesThe binary is at build/debug/lk.
build/debug/lk -l stdlib script.lk:= defines and assigns. = reassigns.
x := 10
x = 20
Method calls use .:
'hello'.toUpperCase
List.new.push!['a', 'b', 'c'].size
A leading . sends to the implicit receiver (self):
.size := 1
.also(Comparable)
Low-precedence chaining uses ->, typically for trailing blocks:
Directory.new['..'].directories -> println
[1, 2, 3].each { v | v * 2 } -> println
{ params | body } for one-liners, { params --- body } for multi-line:
double := { x | x * 2 }
add := { x, y ---
x + y
}
Varargs use ...:
func := { x, rest... --- rest }
func(1, 2, 3) # [ 2, 3 ]
Closures capture their enclosing scope:
maker := { x --- { x += 1 } }
c := maker(0)
c # 1
c # 2
? and ! are the if/else operators:
x > 0 ? 'positive' ! 'non-positive'
++ # string/list concatenation
** # repeat ('x' ** 3 = 'xxx', [1,2] ** 2 = [1,2,1,2])
$ # to string ($[1,2,3] = '1 2 3 ')
! # logical not
&& || # logical and/or
<=> # comparison (-1, 0, 1)
Objects are prototype-based. new clones an object, extend adds slots in bulk, also mixes in another object:
Animal := Object.new
Animal.sound := 'generic'
Animal.speak := { .sound.println }
Dog := Animal.new
Dog.sound := 'woof'
Dog.speak # 'woof'
Animal.extend {
.sound := 'generic'
.speak := { .sound.println }
}
list := [1, 2, 3]
list(0) # 1
list.size # 3
list.each { v | v.println }
map := Map.new
map.set('key', 'value')
map.at('key') # 'value'
include('path/to/file.lk')
src/ C source files
include/ C header files
stdlib/ Link standard library (.lk)
tests/ Test suite
extra/ Extensions and examples
Early development. Expect breaking changes.