Source files#
A .ms file is a module. Top level holds imports, types, functions, constants, and tests. Executable statements and local :=/var bindings go inside a function or test. There is no module declaration or top-level initializer; a top-level := is a constant
.
src/greeting.ms:
export type Customer {
name String
active Bool
}
export fn welcome(customer Customer) String {
if customer.active {
return f"Welcome, {customer.name}!"
}
return "Your account is inactive."
}Blocks and layout#
Braces define blocks, and a statement ends at the end of its line. Indentation is for readers: ms fmt writes one tab per level. Semicolons and tabs between tokens are rejected.
Calls take positional arguments, optional labels, or both; an unlabeled argument is always positional. See declarations and calls .
Expressions inside parentheses, brackets, or braces can span lines:
customer := Customer(
name: "Ada",
active: true,
)Comments start with // and run to the end of the line (a trailing comment follows code on its line). A multi-line comment is a /* ... */ block on its own lines. The comment lines or block directly above a declaration, or a trailing // on its line, document it. See the grammar
for the exact rules.
Source is UTF-8 and case-sensitive. Identifiers use ASCII letters, digits, and underscores; text and comments may contain Unicode.
// A local binding can infer its type from the value.
count := 3Writing concise code#
Manuscript favors one idea per line and the standard form for each task:
fn check(rows List[String], limit Int) String {
if rows.is_empty() { return "empty" }
if rows.any(r => r.length() > limit) { return "too long" }
blanks := rows.count(r => r.is_empty())
kind := if blanks == 0 { "dense" } else { "sparse" }
for i in 0..rows.length() {
if rows[i] == "stop" { return f"stopped at {i}" }
}
print(f"{kind} {blanks}")
return kind
}- Output is
print(x): a line, no import, never fails.stdout().writeis for output whose failure the program handles. - A guard is one line:
if c { return x },if c { continue }. Nothing follows areturnin anelse. - Read with
xs[i]; count withfor i in 0..n { ... }; walk withfor x in xs { ... }; usefor _i in 0..n { ... }when the counter is unused. - Collections are built and tested with
any,all,count,sum,map,filter,fold,[0].repeated(n),a.extend(b)and(0..n), not loops. - Conditions are
x,not x,xs.is_empty(),a.max(b). - A value chosen by a condition is
x := if c { a } else { b }. - An absent value is
o or d,m.get_or(k, d)orif o != null { ... }; aResultis unwrapped with?.
Module boundaries#
A file’s resolved path identifies its module. export makes a declaration visible to other modules:
import Customer from "./greeting.ms"Relative imports resolve from the importing file’s directory. ms.toml configures the source directory, entry file, and import aliases; see modules
and project configuration
.
Exact syntax is in the grammar ; precedence is in expressions .