OxL Reference

kw var

Reserved keyword

The list of words: §1.4

Syntax

ebnf
Receiver    = [ "var" | "move" | "static" ] ;
ebnf
ActorMember = { Attr } ( "var" Ident ":" Type "=" Expr | "dep" Ident ":" Type
            | "msg" Ident "(" [ Params ] ")" [ "->" Type ] Block
            | "on" ( "activate" | "passivate" ) Block ) ;
ebnf
AtomType    = Path [ "<" TypeArgs ">" ] | "(" [ Type { "," Type } ] ")" | "[" Type [ ";" Expr ] "]"
            | "&" [ "var" ] Type | "*" [ "var" ] Type | ( "frozen" | "sync" | "view" | "dyn" ) Type
            | "fn" "(" [ Type { "," Type } ] ")" [ "->" Type ] [ Effects ] [ "escaping" ] | "never" ;
ebnf
Stmt        = ( "let" | "var" ) Pattern [ ":" Type ] "=" Expr | Const | Place AssignOp Expr
            | "defer" Expr | Expr ;
ebnf
Arg         = [ Ident ":" ] Expr | "&" "var" Expr ;
ebnf
PatAlt      = "_" | Literal | Literal ( ".." | "..=" ) Literal | [ "var" ] Ident [ "?" ]
            | Type [ Ident ] | [ "." ] Path "(" [ Patterns ] ")" | Path "{" [ FieldPats ] [ ".." ] "}"
            | "(" Patterns ")" | "[" [ Patterns ] [ ".." [ Ident ] ] "]" ;

Grammar: App. A

Defined in

Examples

oxl
@idle(ACCOUNT_IDLE)
actor Account sharded by id: AccountId {
  var balance: Money = Money.zero()
  @transient var hits: u64 = 0
  on activate { log.debug("account {id} up") }
  msg deposit(x: Money) { balance += x }
  msg balance() -> Money { balance }
}

Account(id).deposit(amount)

— 12.5 Sharded actors

oxl
impl Vec3 {
  static op +(a: Vec3, b: Vec3) -> Vec3 => Vec3(a.x + b.x, a.y + b.y, a.z + b.z)
  static op *(v: Vec3, k: f32) -> Vec3 => Vec3(v.x * k, v.y * k, v.z * k)
  static op -(v: Vec3) -> Vec3 => v * -1.0
  op [](i: usize) -> f32 { … }            // read by index
  var op [](i: usize) -> &var f32 { … }   // write by index
  op ()(t: f32) -> Vec3 { … }             // call as a function
  static op <=>(a: Vec3, b: Vec3) -> Ordering { … }
  op as Vec4 => Vec4(x, y, z, 1.0)
}

— 5.3 Overloading and user-defined operators

Related diagnostics

actor-not-hosted, not-callable, not-overloadable, operator-decl, range-not-iterable, actor-cycle, bad-init, missing-field, must-close, positional-literal, sealed-literal, impl-foreign-type, unknown-method, explicit-interface

See also