Syntax & Blocks
Lexical rules, reserved keywords, comments, indentation vs end blocks, show, and assert.
Lexical Structure
- UTF-8 source: All
.dlfiles must be valid UTF-8. - Comments:
#starts a single-line comment extending to the end of the line. - Identifiers: Case-sensitive ASCII letters, digits, and
_(cannot start with a digit). - Newlines: Terminate statements outside unclosed
(...),[...], and{...}.
Reserved Keywords
Dlang reserves 22 keywords that cannot be used as variable or function names:
keywords
fn end return if else while for in
break continue show assert import match pub private
true false missing and or notIndentation and end Blocks
Blocks (fn, if, else, while, for, match) support both indentation-based scoping and explicit end terminators. Never mix tabs and spaces in the same file.
blocks.dl
# Indentation-only block
fn greet(name)
show "hello " + name
# Explicit end terminator
if true
show "yes"
endOutput & Assertions
show expr prints a value followed by a newline. assert expr aborts at runtime if expr is not true.
io.dl
name = "dlang"
show name
assert len(name) == 5