Zane Functions, Methods, and Lambdas
This document specifies Zane’s function model: functions, methods, subscripts, overload resolution, function values, lambdas, and method name resolution. Data declarations and constructors live in types.md; the package-scope rules that govern these declarations live in packages.md.
See also:
types.md§3 for constructors.memory.md§2 for ownership and&rules.effects.md§2 formut.syntax.md§3 for declaration grammar.
1. Overview
Zane unifies methods, functions, and lambdas under one model: a callable is a package-scope declaration (or anonymous literal) whose first parameter may optionally be this.
Verb. A verb is a callable whose body is a sequence of statements that executes to do work: functions, methods, operators, constructors, and lambdas (a lambda being an anonymous verb). The spec uses “verb” whenever a rule applies to all of these as a group, and reserves “function” for the narrow form — an ordinary identifier-named verb with nothis. A subscript is not a verb — its body must be a place expression that projects a place rather than running computation (§2.9).Package-scope behavior. All methods, functions, and constructors are declared at package scope; type bodies never contain behavior.Methods as verbs. A method is a verb whose first parameter isthis, so methods and functions share one model and differ only by the subject.Capability markers. Surface markers select whether a verb is a method, a constructor, an operator or a lambda, and each marker unlocks a capability: naming the first parameterthisgrants the subject call (a method); naming the verb after a type grants an implicit return type and, for a type with fields,init{ }(a constructor). See §8.Explicit mutation at the call site.:calls are read-only;!calls invokemutmethods.Overload identity is parameter types only. Names, return type, andmutdo not distinguish overloads.
Story:
stories/functions.md— “Pulling methods out of the type body”.
2. Methods
2.1 Methods are verbs whose first parameter is this
A method is any package-scope verb whose first parameter is named this. this MUST be the first parameter and MUST NOT appear in any other parameter position.
The subject is the object a method is called on. Two constructs are named after it and are not interchangeable: this is the subject parameter — the declaration’s first parameter, whose surface form fixes how the object reaches the body (memory.md §2.9) — and the expression to the left of : or ! at a call site is the subject expression, which supplies the object and must satisfy whatever that form requires. Unqualified, “the subject” means the object itself.
Int scaledId(this Node, factor Int) {
return this._id * factor;
}
Story:
stories/functions.md— “Renaming the receiver to the subject”. Story:stories/memory.md— “Bare symbols become guest sources again”.
2.2 this grants the subject call
Naming the first parameter this is the only marker that makes a declaration a method. That token grants the subject call: the method is called on its subject with : or ! (§2.5), and the subject reaches the body as a borrow of the caller’s storage (§2.4). The same parameter type written with another name is a function, called by name (§3.3).
Access to _ fields is decided by package, for a method as for every other verb (types.md §2.3).
package Graph;
Int scaledId(this Node, factor Int) => this._id * factor; // a method: node:scaledId(factor)
Int scaledIdOf(node Node, factor Int) => node._id * factor; // a function: scaledIdOf(node, factor)
Story:
stories/functions.md— “Pulling methods out of the type body”. Story:stories/functions.md— “thiskeeps only the subject call”.
2.3 Read-only methods are the default
A method without mut may read this, its parameters, and reachable read-only state, but it may not write through this.
2.4 Mutating methods use mut
A method marked mut may write to any state reachable through this, whether through an owning field or a reference.
A write to this lands on the caller’s object, because this is a borrow of it for either kind of type (see memory.md §2.9). For a value-type subject the borrow is of the caller’s slot — the actual value, not a copy — which makes the value mutable in place while preserving its value semantics. For a reference-type subject it is the caller’s owner, settled or roaming. Nothing is written on this to select a mode, because a subject has no other. The caller stays a full owner either way.
The borrow is scoped and non-escaping: this may be read and, under mut, written, and may be the root of an & store into the subject (lifetimes.md §1.11), but it is never moved, stored, or returned as &T. A verb that hands out a reference into an object takes that object as an &T parameter instead.
Unit setScale(this Node, scale Float) mut { // reference subject: a borrow of the caller's owner
this.scale = scale;
return Unit();
}
&Weapon mainWeapon(player &Player) => player.weapon; // a reference is handed out by a function
&Weapon weapon(this Player) => this.weapon; // ILLEGAL: this is a borrow
Unit setY(this Vec2, y Float) mut { // value subject: in-place through the borrow
this.y = y;
return Unit();
}
pos!setY(Float(3.0));
2.5 Call markers are part of the surface syntax
Read-only methods are called with :. Mutating methods are called with !.
node:scaledId(Int(2));
node!setScale(Float(3.0));
Calling a mut method with : is illegal. Calling a non-mut method with ! is also illegal.
Story:
stories/functions.md— “Mutation you can see at the call site”. Story:stories/memory.md— “Three ways to hand over an object”.
2.6 Method desugaring
subject:method(arg) → ResolvedPkg$method(subject, arg)
subject!method(arg) → ResolvedPkg$method(subject, arg)
subject:Pkg$method(arg) → Pkg$method(subject, arg)
subject!Pkg$method(arg) → Pkg$method(subject, arg)
2.7 Parameters are read-only
Explicit parameters other than this are read-only. A read-only binding admits no write, and a ! call is a write: it runs a mut method that writes its subject. So a parameter can be neither assigned nor the subject of a ! call, and neither can anything reached through it or any reference derived from it (effects.md §4.1, §4.4). How each parameter is passed — the three reference modes, or a value borrow — is covered in memory.md §2.9.
2.8 Borrow, take, and reference method parameters
A reference-type method parameter selects one of three passing modes (memory.md §2.9):
- A parameter declared as a plain reference type
Tis a borrow: the caller passes any owner, settled or roaming, or a temporary, and stays a full owner. The callee may read it; it may not store, return, or move it. - A parameter declared as
^Ttakes its argument: the caller passes a roaming owner, which is spent (lifetimes.md§1.8), or a temporary. The callee owns it and may move it on, store it, or return it. - A parameter declared as
&Tis a reference: the caller either supplies a settled place undermemory.md§2.8, which mints a reference, or passes an existing&Tvalue. The callee may read it, return it, or store it into an&field or element. The signature records where the reference comes to rest (lifetimes.md§1.11), and the compiler checks at each call whether that store is legal.
Only an &T parameter may be bound into & storage: a borrow is never stored, and a taken owner is roaming, which nothing references. A value-type parameter is always a read-only borrow.
type Car = #struct {
engine &Engine;
_value Int;
}
// a borrow, used only to read
Int calculate(this Car, engine Engine) {
return this._value + engine.speed; // legal: reading through the borrow
}
// `&` parameter stored into an `&` field: recorded in the signature, checked per call
Unit setEngine(this Car, engine &Engine) mut {
this.engine = engine; // legal here; each call compares the two argument paths
return Unit();
}
// a borrow is never stored
Unit setEngineWrong(this Car, engine Engine) mut {
this.engine = engine; // ILLEGAL: a borrow cannot be bound into an `&` field
return Unit();
}
Call syntax is uniform regardless of the parameter mode; only what the caller may supply differs:
engine Engine();
garage Garage();
car:calculate(engine); // legal: a borrow of engine
car!setEngine(engine); // legal: engine is settled, and one scope holds car and engine
car!setEngine(garage.spare); // legal: a field access is a reference source, and
// garage is in the same scope
car!setEngine(Engine()); // ILLEGAL: a temporary is not a place expression
do() {
spare Engine();
car!setEngine(spare); // ILLEGAL: this block does not outlive car's
}
The last two fail for unrelated reasons. A temporary is refused at the source end, by memory.md §2.8; spare is a perfectly good reference source and is refused at the destination end, by the store rule (lifetimes.md §1.1) applied to the paths this call supplied.
2.9 Subscripts are place projections
Subscripts are package-scope declarations with the subject first:
(this CustomList)[index Int] => this._data[index];
(this Tensor3)[x Int, y Int, z Int] => this._data[x][y][z];
The body of a subscript definition MUST be a place expression. [] is not a general function call and cannot return a computed value. Its result is always inferred from the projected place, so subscripts have no explicit return type annotation. A subscript may declare any number of comma-separated parameters inside []; it is not limited to one or two.
When a subject interprets an Int subscript as an ordinal position in an ordered sequence, that position is 1-based. The first element is at 1, and a sequence with n elements uses 1 through n as its positional range.
See also:
memory.md§2.8 for when a place expression may create a new&.
(this CustomList)[index Int] => this._data.compute(index); // ILLEGAL: body is not a place expression
Int (this CustomList)[index Int] => this._data[index]; // ILLEGAL: explicit return type not allowed
list[i] is a place expression only if list is a place expression. CustomList()[1] is therefore not a place expression because the base is a temporary.
A subscript expression denotes the place its body projects, so it is a reference source exactly when that place is (memory.md §2.8). Following the body through every subscript and field it uses ends at one intrinsic projection, which determines the result: an @primitives$ArrayRef element takes its root’s state and may be referenced when that root is settled, an @primitives$ListRef element is always roaming, and an @primitives$Array or @primitives$List element is a value.
type Squad = #struct {
_members ArrayRef<Player, 4>;
}
(this Squad)[index Int] => this._members[index];
squad Squad(...);
lead &Player = squad[1]; // legal: the projection ends at an ArrayRef element of a settled root
Story:
stories/memory.md— “ArrayRef: a fixed reference container whose elements can be guested”.
Story:
stories/functions.md— “Pulling methods out of the type body”. Story:stories/syntax.md— “Callback lists stay inside the parentheses” explains why a subscript is not an ordinary method returning a borrow.
3. Functions
3.1 Functions are package-scope verbs without this
A function is an ordinary identifier-named package-scope verb whose first parameter is not named this. (Operators are named by an operator token and constructors are named after their type, so neither is a function even though they also take no this.)
Float distance(from Vec2, to Vec2) {
dx Float = to.x - from.x;
dy Float = to.y - from.y;
return sqrt(dx * dx + dy * dy);
}
3.2 Functions reach private fields in their own package
A function reaches a _ field on the same terms as a method: when it is declared in the package that declares the field’s type, and never from another package (types.md §2.3).
3.3 Functions use ordinary call syntax
Functions are called as name(args...) or packageName$name(args...).
3.4 Expression-bodied verbs
A verb may use => for its body. Functions, methods, operators, constructors, and lambdas all support this shorthand (operators are covered in operators.md, constructors in types.md §3.2):
Int double(value Int) => value * 2;
Int scaledId(this Node, factor Int) => this._id * factor;
Unit noOperation() => Unit();
=> expr is purely a surface shorthand: it stands for exactly { return expr } and adds no other behavior. A constructor’s => init{...} is the same rewrite — Vec2(x Float, y Float) => init{x; y;} is shorthand for { return init{x; y;} }.
3.5 Block-bodied verbs return explicitly
Every block-bodied verb must return a value explicitly on every returning path, including a verb whose return type is Unit:
Unit noOperation() {
return Unit();
}
The return checker does not synthesize a constructor call for Unit or any other singleton type.
Story:
stories/functions.md— “Every return carries a value”.
3.6 A computation is a function, an operation on a subject is a method
A verb that computes its result from its inputs is declared as a function, even when its first parameter has the type the result is computed from. A verb that reads its subject’s own state or acts on its subject is declared as a method. core and math follow this rule, and a package SHOULD follow it too.
Float sqrt(value Float) => Float(@math$sqrt(value)); // a computation: sqrt(x)
Float scale(this Node) => this.scale; // a read of the subject: node:scale()
Unit setScale(this Node, scale Float) mut { // an act on the subject: node!setScale(s)
this.scale = scale;
return Unit();
}
So sqrt(x), min(a, b), and atan2(y, x) are calls by name, with every input written in the same position, and a method’s subject is always the object whose state it reads or writes.
Story:
stories/functions.md— “Computations are functions, and math functions with them”.
4. Overloading Rules
4.1 Overload identity is parameter types only
Two declarations in the same package conflict when they have the same ordered parameter types. Parameter names, this, mut, and return type do not distinguish overloads.
Two overloads MUST NOT differ only by the passing mode at the same parameter position — that is, only by whether that position is T, ^T, or &T, or, for a parameter of @concepts$Array type, only by whether its element is (generics.md §3.2). Such declarations are illegal and the compiler MUST reject them with a compile-time error, for example: “illegal overload set: differs only by the passing mode on a parameter; rename one declaration or choose a single signature.”
Unit consume(this Car, engine ^Engine)
Unit consume(this Car, engine &Engine) // ERROR: differs only by the passing mode
Unit fleet(engines @concepts$Array<^T Type, n @concepts$Int>)
Unit fleet(engines @concepts$Array<T Type, n @concepts$Int>) // ERROR: the same, on each element
The mode changes what the caller must supply and what state the call leaves the caller in — not the shape of the call. Overloading on it would give consume(e) two different effects on e’s ownership with nothing at the call site to tell them apart, and fleet([e]) two such effects on each element.
Two overloads MUST NOT differ only by the mut of a function-type parameter at the same parameter position either. A function value that does not declare mut may be passed where a mut function type is expected (§7.2), so it would match both.
Unit tune(f Unit[this Engine])
Unit tune(f Unit[this Engine] mut) // ERROR: differs only by `mut` on a function type
Story:
stories/functions.md— “Lambdamutpermission in overload matching”.
4.2 Consequences of the overload identity rules
Declarations that differ only by return type, parameter names, this, mut, or the mut of a function-type parameter are compile-time conflicts.
4.3 Valid overloads differ by arity or parameter type
Legal overload sets must differ in the number of parameters or in at least one parameter type at the same position, ignoring the passing mode.
Story:
stories/functions.md— “Overloading on shapes, and only shapes”.
5. Overload Resolution with Implicit Constructors
For function calls, constructor calls, and desugared method calls, overload resolution proceeds in three phases:
- Direct match. A candidate is viable only if the call type-checks with no implicit constructor insertions. If exactly one candidate is viable, it is selected. If more than one candidate is viable, the call is an ambiguity error.
- Generic match. If the direct phase finds no viable candidate, the called declaration’s inline-introduced type and number parameters are inferred from the static types of the call arguments: a type parameter from an argument’s type, a number parameter from the number part of an argument’s type. A call never carries a
<>type-argument list; a type or number may instead be passed as an ordinary argument to aTypeor@concepts$Intvalue parameter (seegenerics.md§5). Inference proceeds under the rules ofgenerics.md§3 and §5, still with no implicit constructor insertions. If exactly one candidate is viable, it is selected. If more than one candidate is viable, the call is an ambiguity error. - Implicit match. If the direct and generic phases find no viable candidate, implicit constructors may be inserted at coercion sites. If exactly one candidate is viable, it is selected. If more than one candidate is viable, the call is an ambiguity error.
If no phase yields a viable candidate, the call is a normal no-match type error.
Implicit constructors are therefore a last resort. They never participate in discovering an otherwise unknown destination type for generic inference.
An operator call resolves through the same phases. Its operands are not coercion sites (operators.md §2.7), so the implicit phase adds no candidate to it.
These phases describe static overload resolution. Matching a variant on its cases is not part of overload resolution at all; it is a separate construct — the match block — that dispatches on the live tag at runtime. See adt.md §5.
See also:
types.md§4 for the definition and constraints of implicit constructors.adt.md§5 for variant matching.
Story:
stories/functions.md— “Overloading on shapes, and only shapes”.
6. Method Name Resolution and Extension Methods
6.1 Unqualified method lookup
For subject:methodName(...) or subject!methodName(...), the compiler resolves candidates in this order:
- the subject type’s home package, which for a fundamental type is
core— for a type supplied by the compiler, its home is the intrinsic namespace that holds it, soruntime!setThreads(...)on an@runtime$Runtimefinds the methods@runtime$declares - the current package, apart from its methods whose subject is a type parameter, which step 3 searches
- the methods whose subject is a type parameter (
generics.md§3.7) that the file writes unqualified: those of the current package, and those an import spells bare (import core$,import core$work)
A method whose subject is a type parameter has no declaring subject type, so step 1 never reaches it. A file whose import qualifies its package names it with that qualifier, as a qualified method call (§6.2): machine!core$work(...) under import core. The compiler searches step 3 only when the first two leave no candidate, so a method declared for the subject’s own type wins over a method declared for every type.
If no candidate matches, the call is a compile-time error. If multiple candidates remain after overload resolution, the call is a compile-time error and must be written with an explicit package qualifier. Because the subject type’s defining declarations are searched first, an unqualified call resolved by step 1 or 2 resolves the same way in every file of the calling package, independent of which packages that file imports. Only a call that neither reaches depends on the file’s imports, through step 3.
6.2 Qualified method calls
Cross-package extension methods are written explicitly:
vec:Physics$kineticEnergy();
To call a method that an intrinsic namespace supplies, a program qualifies the method with that namespace in the same way. The worker intrinsics are such methods, on a subject of any type, so a program calls one as this!@controlflow$work(step) (control-flow.md §4.1).
6.3 Extension methods may be declared in any package
Because methods are package-scope verbs, any package may define methods on imported types. Such a method has the subject call of any other method (§2.2) and reaches only the type’s public fields, because its _ fields are private to the type’s package (types.md §2.3).
Story:
stories/functions.md— “Pulling methods out of the type body”. Story:stories/functions.md— “thiskeeps only the subject call”.
7. Function Values and Lambdas
7.1 Callables cannot be referenced as values
Methods, functions, and operators are call-only. A package-scope callable name may appear only in call position; there is no syntax that turns it into a value. For example, + can be called, but + cannot be written as a value.
Graph$scaledId(node, Int(2)) // legal: call position
Graph$scaledId // ILLEGAL: callables cannot be referenced as values
The reason is the same as the reason operators are safe to overload. An overloaded name is not a single value; it is a set of candidates that only collapses to one when arguments are supplied at a call site. In value position there are no arguments, so nothing selects a member of the set. Passing an overloaded callable into an overloaded parameter would have to choose on both sides at once with no information to choose from. Making callables call-only removes that whole class of ambiguity by construction.
See also:
operators.md§5.3 for the parallel rule on operators.
Story:
stories/functions.md— “Names that are not values”.
7.2 Lambdas are self-typed function values
A lambda literal is a function declaration with the name removed. It writes its own parameter types, return type, abort type, and mut (see syntax.md §3.8). Nothing is inferred from context.
callee(Float(x Int) {
small Bool = if(x < Int(10)) {
return Float(0.0);
}
small:else() {
return Float(1.0) / Float(x);
}
});
Because a lambda carries its complete type, it is a single value with one exact type. It can therefore be passed to an overloaded callee without ambiguity: the lambda fixes its own type, so overload resolution on that callee proceeds with ordinary argument types and no circularity. Its complete written type also allows it to be defined and passed directly in the same expression without depending on surrounding context.
mut is part of the lambda’s written type. A lambda that does not declare mut may still be assigned or passed to a mut function type — it simply does not use the mutation permission — but a mut lambda may not be assigned or passed to a non-mut function type:
onEventCallback Unit[this Node, EventData] mut = Unit(this Node, data EventData) {
...
return Unit();
} // OK: non-`mut` lambda assigned to a `mut` function type
readonlyCallback Unit[this Node, EventData] = Unit(this Node, data EventData) mut {
...
return Unit();
} // ILLEGAL: expected a non-`mut` function value
7.3 Lambda-variables hold function values
To name a function value, declare a lambda-variable: a symbol bound to a lambda literal. The shorthand mirrors constructor-call instantiation, swapping the name and return type relative to a function declaration:
Float callback(x Int) { ... } // function declaration
callback Float(x Int) { ... } // lambda-variable declaration
A lambda-variable is an ordinary symbol with a single function type. Because a symbol cannot be redeclared with a different type, a lambda-variable name can never accumulate an overload set, so it is always unambiguous in value position. This single type makes callee(callback) well-defined where referencing an overloaded callable would not be.
See also:
syntax.md§2.13 for function types and §3.8 for lambda literals and lambda-variable declarations.
7.4 Lambdas do not capture
Lambdas MUST NOT capture outer variables. Every dependency must be passed as a parameter or supplied through surrounding storage explicitly. See concurrency.md §5.2 (“Lambdas do not capture”).
A block argument is not a lambda and does capture. It is a source construct rather than a value: it has no written type, cannot be stored, and cannot outlive the call it is written at, so nothing can run it from a frame the compiler is not looking at. See control-flow.md §2.
Story:
stories/functions.md— “Names that are not values”.
7.5 No bound method references
Zane does not provide bound method references as a separate feature. Because lambdas do not capture, there is no syntax that implicitly stores a subject inside a function value. Code that needs a subject later must keep that subject in ordinary storage and pass it explicitly when the function value is invoked.
7.6 Generics are orthogonal to overloading for function values
A lambda is a single value with one exact type, even when that type is a function type (§7.2). Overload identity is parameter types only (§4.1), so a function type is a single, unique parameter shape. Passing a lambda to an overloaded callable is therefore a shape match at that parameter position, exact up to the mut permission of §7.2, not a contest the lambda must win.
The circularity that makes overloaded names unusable as values (§7.1) does not apply to a lambda. An overloaded name is a candidate set with nothing to collapse it in value position; a lambda is already a single value. That distinction — not genericity — is what lets a self-typed lambda be passed to an overloaded callable while a bare callable name cannot.
A function value that is itself generic — polymorphic over its own type or number parameters — is not specified in this version. The open question is its runtime representation (monomorphization versus dictionary passing), which is a memory-model decision, not an overload-resolution or type-checking one: a generic function type would still be a unique parameter shape under the rules above. See generics.md §9.
8. The Verb Model and Capability Markers
Every callable in Zane is a verb (§1). Whether a declaration is a function, a method, a constructor, an operator, or a lambda is determined entirely by a small set of surface markers, and each marker unlocks a specific capability. There is no separate mechanism per callable kind; there is one verb, and markers select its capabilities.
8.1 One model, selected by markers
| Marker | Verb kind | Capability unlocked |
|---|---|---|
First parameter named this |
Method | : / ! call syntax on a borrowed subject |
| Name is a type | Constructor | Return type is the named type (no return annotation); init{ } for field initialization when the type has fields |
| Name is an operator token | Operator | Operator-position calls |
| No name | Lambda | Anonymous function value |
| Plain identifier, none of the above | Function | No special capability |
The markers are largely independent — a lambda may still declare a this subject (§7.2), for example — but the markers present distinguish the kinds of verb above. A constructor body and a method body are otherwise ordinary verb bodies (§2, §3).
8.2 init{ } parallels this
The marker model makes the constructor/function relationship exact: a constructor is a verb whose name is a type, optionally with a .name suffix that distinguishes a named constructor (see types.md §3.4). Naming a verb after a type has two effects and no others — it makes the return type implicit (the verb produces the type it names, the suffix notwithstanding) and, when the type has fields, it unlocks init{ } (see types.md §3). Every mould may declare constructors (types.md §3.1). This mirrors methods precisely: naming the first parameter this is the only marker that makes a verb a method, and that token alone unlocks the subject call (§2.2).
So init{ } is a capability gated by a naming convention, exactly as the subject call is. A plain function cannot use init{ } for the same reason it cannot be called on a subject: it lacks the marker that grants the capability. A function that needs to build a value calls the constructor instead (see types.md §3).
8.3 What is shared, and what the markers change
All verbs share one parameter system (see generics.md §3), one body grammar, one overload-resolution procedure (§5), and one effect model (§9). The markers do not touch any of these. Comparing functions, methods, and constructors, the markers change only two properties: whether a return type is written, and which capability is granted — the subject call for this, init{ } initialization for a type name with fields. (The operator and lambda markers likewise change call syntax and value representation; see the §8.1 table.) Functions and constructors share the same verb model, separated only by the name-is-a-type marker.
See also:
syntax.md§3 for the declaration forms of each verb kind.types.md§3 for constructors and theinit{ }expression.operators.md§2.2 for operator declarations.
Story:
stories/functions.md— “Pulling methods out of the type body”.
9. Connection to the Effect Model
mut marks the one path by which a verb writes state its caller can see: the state reachable through this. A read-only method or a function writes none of it, and reads capability-backed state only through : calls on a capability. This is why overload identity ignores mut: the call contract is structurally the same even though the behavioral permissions differ.
See also:
effects.mdfor the complete effect model and concurrency implications.
10. Summary
| Concept | Rule |
|---|---|
| Verb | A callable; markers select the kind of verb it is, and each marker unlocks a capability |
| Capability markers | this first → method (subject call); name is a type → constructor (implicit return, and init{ } for a type with fields); operator token as name → operator; no name → lambda |
| Method | Package-scope verb whose first parameter is this |
mut method |
Called with !; may mutate state reachable through this, which is a mutable borrow of the caller’s value or owner |
| Read-only method | Called with :; may read but not write this |
| Function | Identifier-named package-scope verb without this; called by name |
| Function or method | A computation from inputs is a function; a read of, or act on, a subject’s own state is a method |
| Block-bodied return | Every returning path uses return expr; Unit receives no fallthrough or bare-return exception |
& method parameter |
Caller supplies a settled place or an existing &T value; callee may read it, store it into & fields, or return it |
Parameters other than this |
Read-only: never assigned and never the subject of a ! call, and neither is any reference derived from one |
Plain T method parameter |
A borrow: caller passes any owner or a temporary and keeps it; callee may read it, never store, return, or move it |
^T method parameter |
Takes: caller supplies a move-source — a roaming owner symbol, which is spent, or a temporary, which has no symbol to spend; callee owns it |
this |
Always a borrow, mutable under mut; never moved, stored, or returned as &T, and nothing is written on it to select a mode |
| Subscript | Package-scope place projection written (this T)[...] => placeExpr; no explicit return type |
| Overload identity | Parameter types only; not names, return type, or mut; overloads differing only by the passing mode (T / ^T / &T, on a parameter or its @concepts$Array element), or by the mut of a function-type parameter, at one position are illegal |
| Overload resolution phases | Direct match, then generic match, then implicit match; ambiguity within any one phase is an error |
| Callable reference | Illegal; methods, functions, and operators are call-only and have no value form |
| Lambda | Self-typed function value: explicit parameter types, return type, abort type, and mut; no capture |
| Block argument | Not a verb and not a value: a braced run of statements passed to a call, which captures and cannot escape (control-flow.md §2) |
| Lambda-variable | Symbol bound to a lambda literal; has one function type; the only way to hold a function value |
| Generic function value | Not specified in this version; deferred on runtime-representation grounds, not overloading (see generics.md §9) |
| Unqualified method lookup | Searches the subject’s home package (core for a fundamental type, the intrinsic namespace for a compiler-supplied type), then the current package, then, when neither has a candidate, the type-parameter-subject methods the file writes unqualified |
| Extension methods | Any package may declare methods on imported types by naming the first parameter this |