Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Keywords

Every Ling keyword has an English spelling and spellings in Chinese, Japanese, Korean and Thai. The lexer turns each spelling into the same token, so you can write a whole program in one language or mix them. This page lists every keyword, its spellings, and what it really does today.

Some keywords are reserved for future features and do nothing yet. They are marked below, so you won’t be surprised when stop doesn’t leave a loop.

Spellings

Where a cell has more than one spelling, all of them work. The first one is the usual choice. These spellings come from the lexer (src/lexer/mod.rs), which is what the runtime actually accepts. In a few places it differs from lexicons/*.ling, and the lexer wins: for example Japanese choose is 選択, Korean form is 구조, and Thai form is โครงสร้าง.

English中文日本語한국어ไทย
bind令 灵符束縛 バ바인드 묶ผูก
do执実行 執실행ทำ
fn函関数 関함수ฟังก์ชัน
if若 如もし만약 조건ถ้า
else否 否则他아니면มิฉะนั้น
while循 当間 一方동안 반복ขณะที่
for历繰 ために위해สำหรับ
in于の中안에ใน
match配一致매치จับคู่
return归戻る 帰る반환 귀환คืน
form形 形式構造구조โครงสร้าง
choose选 选择選択선택เลือกแบบ
mod核モジュール 模모듈โมดูล
use载 引使う사용ใช้ นำเข้า
as为として로서เป็น
ok好 可良い좋아ตกลง
bad坏 误悪い나쁨ผิดพลาด
true真真참จริง
false假偽거짓เท็จ
try试 尝试試す시도ลอง
type符型타입ชนิด
where条件但し단โดยที่
async异 异步非同期비동기ไม่พร้อมกัน
wait待 等待待つ기다려รอ
own独 拥有所有소유เป็นเจ้าของ
lend借貸す빌려ให้ยืม
share共 共享共有공유แบ่งปัน
move移 移动移動이동ย้าย
copy复 复制複製복사คัดลอก
stop止停止 止まれ 停め멈춤หยุด
again继续継続계속ทำอีก
change变 改变変える변경เปลี่ยนแปลง
post出 发布投稿게시ส่ง
give予 给渡す전달ให้
fit适合適合적합เหมาะสม
can能できる가능สามารถ
sure确 确定確か확실แน่นอน
maybe或 可能多分아마도อาจจะ
pure纯純粋순수บริสุทธิ์
spawn启 生成起動생성สร้าง
none无なし없음ไม่มี

asm has an English spelling only.

What each keyword does

KeywordStatusWhat it does
bindactiveCreates or replaces a binding. Also defines globals and the entry point.
doactiveA block whose value is its last statement.
fnactiveDeclares a function.
if / elseactiveConditional expression.
whileactiveLoop while a condition holds. The body shares the outer scope.
for / inactiveLoop over a range or list. Each pass gets a fresh scope.
matchactivePattern matching.
returnactiveLeaves the current function with a value.
formactiveDeclares a record type.
chooseactiveDeclares an enum type with optional payloads.
modactiveGroups functions into a namespace (name::f()).
use / asactiveLoads another file, optionally under an alias.
ok / badactiveBuild a result, and match one as a pattern.
true / falseactiveThe boolean values.
trybuiltinNot syntax: the builtin try(f, args...). Works on the interpreter only.
typeignoredtype Name as T is parsed and thrown away. It swallows what follows it, so avoid it.
whereignoredfn f(x) where ... { }: everything up to { is skipped.
asyncignoredasync fn runs synchronously, like a normal function.
waitunreliableGives the value on the interpreter but () on the JIT. Don’t use it.
own lend share move copyignoredPrefix words that return their operand unchanged. No ownership checks happen.
asmignoredasm("...") is meant for bare-metal builds. In a normal run it does nothing useful.
stopreservedDoes not break out of a loop.
againreservedDoes not continue a loop.
changereservedDoes nothing. Rebind with bind instead.
post give fit can sure maybe purereservedDo nothing. They are ordinary names to the parser.
spawnreservedDoes nothing, and there is no spawn builtin.
nonereservedNot a value. The interpreter reports undefined: 'none'. Use () for “nothing”.

Reserved words are ordinary names to the parser, so bind stop = 2 is legal. On the interpreter, a bare stop or again in a loop is an undefined error; on the JIT it is silently ignored and the loop keeps going.

Active keywords

bind

bind name = expression is the only way to create or “change” a variable. Binding a name again replaces it. See Bindings.

bind start = do {
  bind price = 40
  bind price = price + 2
  println(price)
}
42

do

do { ... } runs statements in order and gives the value of the last one. The entry point is a do block bound to start. See Blocks.

fn and return

fn name(params) { body } declares a function. The last expression is the result, and return leaves early.

fn describe(n) {
  if n > 100 { return "big" }
  "small"
}
bind start = do {
  println(describe(500))
  println(describe(5))
}
big
small

A return directly inside start ends the program quietly on the JIT and is an error (unexpected top-level return) on the interpreter.

if, else, while, for, in

The control-flow keywords are described in Control flow. There is no break or continue: stop and again are reserved words only. To leave a loop early, return from a function:

fn find(xs, target) {
  for x in xs {
    if x == target { return true }
  }
  false
}
bind start = do {
  println(find([1, 2, 3], 2))
  println(find([1, 2, 3], 9))
}
true
false

match

match value { pattern => expression, ... } evaluates the first arm whose pattern fits. Patterns are _, literals, a name, ok(p) / bad(p) and enum variants. See match.

form and choose

form declares a record type and choose an enum. See Records and enums.

choose Light { Red, Yellow, Green }
fn action(l) {
  match l {
    Red() => "stop",
    Yellow() => "slow",
    Green() => "go"
  }
}
bind start = do {
  println(action(Green()))
  println(Red().tag)
}
go
Red

mod, use, as

mod name { ... } groups functions, called as name::f(). use "file.ling" loads another file, and use "file.ling" as m makes its functions available as m::f(). See Modules and Projects.

ok and bad

ok(value) and bad(reason) build results. In a match they are patterns. A bad result prints as Err(...). See Errors and Results.

fn half(n) {
  if n % 2 == 0 { ok(n / 2) } else { bad("odd number") }
}
bind start = do {
  println(half(10))
  println(match half(7) { ok(v) => v, bad(e) => "error: " + e })
}
Ok(5)
error: odd number

true and false

The boolean literals. They are the values if and while should be given.

Keywords that are parsed but ignored

The ownership words own, lend, share, move and copy can stand in front of an expression (or a parameter name) and are then ignored. There is no borrow checker, and using a value after move is fine:

bind start = do {
  bind a = own [1, 2, 3]
  bind b = move a
  println(a)
  println(b)
}
[1, 2, 3]
[1, 2, 3]

async fn declares an ordinary function that runs immediately when called. where clauses after a function’s parameters are skipped:

async fn work(n) { n * 2 }
fn next(x) where x { x + 1 }
bind start = do {
  println(work(4))
  println(next(2))
}
8
3

For real parallel work, use the thread_* builtins.

Words that look like keywords but aren’t

  • start, main, 启, เริ่ม and 시작 are names, not keywords. The runtime looks for them to find the entry point. See The entry point.
  • result, loop, break, continue, struct, enum, let, const and similar words appear in some lexicon files but are not keywords. Ling has no loop and no let: use while and bind.
  • number, text, bool, list, map and tuple are documentation words only. Ling is dynamically typed. See Types and Values.