kw let
Reserved keyword
The list of words: §1.4
Syntax
Stmt = ( "let" | "var" ) Pattern [ ":" Type ] "=" Expr | Const | Place AssignOp Expr
| "defer" Expr | Expr ;If = "if" ( Expr | "let" Pattern "=" Expr ) Block [ "else" ( If | Block ) ] ;While = [ Label ":" ] "while" ( Expr | "let" Pattern "=" Expr ) Block ;Grammar: App. A
Defined in
- 4.1 Variables and constants — There are no mutable globals without sync.
- 4.3 Construction and constructors — Literal. T{ f1: e1, f2, ..base }
- 5.9 Query expressions — Form: from x in source (where e)\* (order by e (asc|desc)?, …)?
- 8.5 Structured concurrency — spawn is allowed only lexically inside scope { …
- 5.7 Lambdas and closures — .field and .method(args) in argument position are shorthand for a lambda with one parameter.
- 8.4 Chains — A chain links asynchronous steps so that either the whole chain is executed or the first unhandled error is returned.
- 5.4 Conditions — There is no ternary operator.
- 0.2 Notation — The grammar is written in EBNF (appendix A)
Examples
let top = from o in db.Order
where o.userId == uid && o.total > MIN_TOTAL
order by o.createdAt desc
skip page * PAGE_SIZE
take PAGE_SIZE
load(items)
let names = from u in users where u.active select u.name // in-memory List
let byRole = from u in users group by u.role into g select (g.key, g.count())let (a, b) = scope {
let ha = spawn loadA()
let hb = spawn loadB()
(ha.join()?, hb.join()?)
}Related diagnostics
global-mutable, mutate-immutable, bad-init, missing-field, must-close, positional-literal, sealed-literal, query-not-sql, spawn-outside-scope, it-outside-chain