Stories: Syntax
See also:
spec/syntax.md— the forms these chapters explain.
The order assignment forced
The first question a declaration syntax has to answer is whether the type is written at all. The rest of this chapter is downstream of the answer, so it is worth stating the case against inference plainly rather than assuming it. The argument for inference is that the type is already determined — number = 2 fixes an integer whether or not anyone writes Int — so writing it again is redundant, and a compiler that can recover the information should. That argument quietly takes a declaration’s job to be informing the compiler. It is not; the compiler was never the reader in difficulty. A declaration’s job is to say, at the place a reader looks, what this name now holds. Calling the type “excess information” is a claim about the compiler’s needs dressed up as a claim about the source, and the trade it actually makes is to delete the only token that answers the reader’s question in exchange for a saved keystroke. So types are written, everywhere — every declaration in Zane names its type, and the language infers nothing about it — and the captured-intent bet is the reason: the source states the author’s intent, and the compiler is not the party being spared.
Once the type is mandatory, the question is where on the line it goes, and it looks at first like a coin flip. We went looking for a language that had already answered it without falling back on inference, and found one: C++, whose construction form writes Int number(2) — the type, the name, the constructor arguments, no = and nothing inferred. It is a genuinely elegant line, and for a while it was the model. The type leads, which suits a reader scanning a column of declarations for a shape, and the constructor arguments ride along in parentheses with no assignment operator in sight.
The declaration was not the reason we rejected it. It was every other place in a program where a type meets a value, and the sharpest of those is overwriting a field. Carry the same shape over and a field write reads:
player.health(20)
Three problems appear at once, and each is worse than the last. The line is ambiguous with a method call — player.health(20) is exactly what invoking a health method on player would look like, and nothing in the text separates the two. The type is not written at all, so the explicitness we had just refused inference to preserve has gone missing at precisely the site where a reader most wants it. And nothing in the line signals a store; an overwrite is a consequential act and it reads here like an expression evaluated for its own sake.
So a field write has to name its type and mark itself as a store: player.health = Int(20). Which raises the question the whole chapter turns on — if the C++ shape works for a declaration and not for a write, where is the difference? Put the two forms side by side and it is not subtle:
Int number(2);
player.health = Int(20);
The type is on the left in one and on the right in the other. These are the same act — produce a value of some type, put it in a named place — written in two directions. The tell is the result of repairing the declaration instead of the write. Move the construction to the side the write puts it on and the declaration becomes:
Int(2) number;
and the conflict is now in plain sight. Int cannot be both the type annotation on the left and the constructor call on the right; it is one token doing a job that has two sides to it. Assignment settles which side wins, because assignment’s direction is not ours to choose — the value comes from the right and lands on the left, in every language anyone has written and in every line of arithmetic anyone learned before that. The constructor is a value-producing expression, so it belongs on the right, and the place being written belongs on the left. Everything else follows from that one fixed point.
What follows is that the name leads. A declaration writes its symbol, then its type, then constructs:
number Int(2);
player.health = Int(20);
and the short form is shorthand for the long form — number Int(2) means number Int = Int(2), which is the field write with a type annotation in front of the destination. The two lines are now the same line with and without a declaration on it. Int appears once as a type and once as a constructor, in that order, in both; the shorthand’s whole content is that when those two are the same name you may write it once.
The cost is a token, and it is fair to name it rather than pretend the shorthand is free. Written out, number Int = Int(2) says Int twice, and the reason the language offers a shorthand at all is that the doubling is real and would otherwise be paid on every line. We are buying explicitness with repetition, collapsing the repetition where we can, and still paying it at every field write — player.health = Int(20) names the type each time, forever, where a language with inference writes player.health = 20. That is the bill for refusing inference and we do not think it can be argued away; the position is that the token is worth its information.
The second cost is subtler and it is a debt owed to a different document. number Int(2) is two identifiers with nothing between them, and it is only readable because the second identifier is obviously a type — which it is only because casing separates types from values. Written in a language where number int(2) were legal, this form would be unreadable mush. The order we chose is affordable because of a rule that was decided on other grounds, and it would not survive that rule being relaxed.
One shape, and everywhere it turned up
Having settled the order for one kind of declaration, we did not go on to design forms for the others. The shape name Type(args) turned out to fit them already, which reads as design and mostly was not; the forms met because each was the same act underneath — name a place, state its type, build its value.
Named constructors and variant cases slot in first: the type position accepts a qualified Type.member, so v Vector2.diagonal(Float(3)) and e Expr.intLit("5") are the one form with a longer name in the type slot, and the types story recounts how those two arrived at one spelling from opposite directions. A package constant is the same line at package scope. A defaulted entry in a field-constructor header is written name String("Pistol") — a constructor parameter with a default, spelled exactly like the declaration it will initialize, because it is that declaration form reused. And a lambda variable is the same line again with a function type in it, which the next chapter takes up on its own, because that form did not fall out — it was rejected elsewhere first and arrived here by a longer road.
There is one seam in all this reuse and it is worth pointing at, because a reader trips over it once and remembers it with irritation. A bare name Type, with no construction after it, is not a declaration — symbols require direct initialization and the bare form is illegal as a statement. But inside a field-constructor header the very same text is legal and has another meaning: a required input the caller must supply. So the same two tokens are an error in one brace and a parameter in another, and only the enclosing body distinguishes them. We accept it because a required constructor input genuinely has no value to write — that is what “required” means — but it is a real wrinkle, and the alternative of minting a separate marker for it would have spent grammar to make a rule that context already settles.
Two orders, and the order we had already turned down
The shape does not reach the one declaration a reader meets most often: a named verb puts its type first, exactly as the C form this story opened by rejecting does:
Unit shoot(this Player) mut { ... }
callback Unit(this Player) mut { ... }
Both of those are legal, they sit in the same files, and they are in opposite orders. That looks like the inconsistency the first chapter set out to remove, so it is worth recounting the history, including the part where we tried it the other way and did not like it.
The C order was there first — the language used it from the beginning, before any of the reasoning about declarations had been done — and when that reasoning arrived we did go back and try the consistent order. add Int(a Int, b Int) is a perfectly writable form and we lived with it for a while. Its flaw is that it detaches the name from the definition. Int add(a Int, b Int) reads as one phrase — a function that takes these and gives back an Int — with the name sitting inside the phrase where it belongs. add Int(a Int, b Int) reads as two pieces: an identifier, and then a specification attached to it. The definition stops being a sentence about the function’s work and becomes a label with a signature bolted on. We should be honest that this is a judgement about how a line reads and not a derivation from anything; nobody can be shown to be wrong for preferring the other order. It is an aesthetic call, we made it, and we kept it.
The episode is worth recording because the rejected form was not wasted. It was waiting for a job we had not yet created. Overloading means a bare callable name denotes a set rather than a value, so a function name cannot be an expression — the functions story explains why that had to be true — and the moment it became true, being able to make a function value stopped being a convenience and became load-bearing, because callbacks are real and some value has to carry them. A lambda is that value; a symbol holding one is a lambda variable. And a symbol holding a value is precisely what the first chapter settled the order for. So:
add Int(a Int, b Int) { ... }
add Int[Int, Int] = Int(a Int, b Int) { ... }
The second line is the meaning of the first, and it is the declaration shorthand with a function type where Int would be and a literal where the constructor call would be. The form we turned down for a named verb turned out to be exactly right one step over.
Seen from here the two orders stop being an inconsistency and start being a distinction the surface is drawing. A return-type-first line defines a verb. A name-first line declares a symbol, and its type happens to be a function. Those are different acts — one adds a callable to a package, the other puts a value in a named place — and a reader can tell which is which at a glance, by the same signal that separates a declaration from a definition everywhere else in the file. The two forms differ by one token swapped, which is either elegant or a trap depending on your mood; it is the former because the swap tracks a real difference rather than decorating one.
That expansion also settles a bracket. Int[Int, Int] is the type, Int(a Int, b Int) { ... } the literal, and they cannot both use ( ) — written the same way, callback Unit(this Player) mut would be a symbol of function type and a lambda variable missing its body, with nothing in the text to say which. So the type takes [ ] and the literal keeps ( ); the choice of which one moves is settled by the bracket rule, under which a flat ,-separated list is [ ] territory. There is no -> for the same reason there is no var: the return type already leads, so an arrow would mark a direction the word order has stated, and it would spend width on the line least able to afford it.
One verb declaration wears neither order:
(this CustomList)[index Int] => this._data[index]
A subscript is a method — it takes a subject and it reaches that subject’s private fields like one — so written as an ordinary method its parameters would sit together, (this CustomList, index Int) => .... The call site pulls them apart. A subscript is invoked as list[i], with the indices in a [ ] that trails the subject, and the declaration splits its parameters to match: subject in ( ), indices in the trailing [ ]. The declaration is shaped like the call it answers. No return type is written because there is none to write — the body must be a place expression, so the result type is whatever the projected place already is, and declaring it would restate a field type the container has already fixed.
That is the honest account and it is thinner than the rest of this file, so it should be labelled as such: subscripts have not been revisited since they were first written down. Nothing has pushed on them, no alternative was weighed at length, and the shape above is a first draft that has survived by not being tested rather than by winning anything. If a later pass finds a better form it will not be overturning an argument, because there is not much of one here to overturn.
Words are paid for by the line
The other standing pressure on Zane’s surface is width. This is not the familiar claim that keywords are bad; keywords are fine, and the language keeps the keywords that earn their place. The claim is narrower and more mechanical: a signature is where a language spends its horizontal budget, and a Zane signature is already carrying a return type, an abort type, a subject, parameter names with their types, and possibly a mut. Every word added to that line is width spent on grammar rather than on the code’s subject, and past some length a signature stops being read and starts being skimmed. So words are bought, not assumed.
That is why there is no var or let in front of a declaration, and no func or def in front of a function. Neither would give a reader any fact the line does not already show — a name followed by a type followed by arguments is a declaration whatever word precedes it, and a return type followed by a name followed by a parameter list is a function. A word whose whole content is to announce the construction it precedes is a word the construction announces itself.
The same reasoning retires the : that Pascal, ML, TypeScript, Rust, and most of their descendants put between an identifier and its type. Its job is to signal that what follows is a type, and it is a perfectly good signal in a language where name type and name value are indistinguishable strings. In Zane they are not: under the casing rule a type’s first letter has already given the answer by the time the : would arrive. The separator carries no information anything else does not already carry, so it goes. What Zane does keep is every word that names an act nothing else names — type, alias, import, return, match, spawn, implicit, mut, this — and it went as far as removing if and while from the grammar entirely, which the control-flow story records as its own episode. The budget is not zero. It is spent on words that do work.
We should be honest about what kind of argument the last paragraph is. “Not needed” is the necessary half and it is not the whole of it: we also simply think the uncluttered line reads better, and that is a judgement about taste, made openly, not a deduction. A reader who finds name: Type more legible than name Type is not making an error we can point at; they are disagreeing about a real trade-off.
And the density has a cost that lands squarely on tooling and on eyes. A declaration with no keyword and no separator is the shortest it can be, which also makes it the least redundant: there is no second signal to catch a misread, so a miscased identifier makes a line with a different meaning and nothing to flag it. Nor can you find declarations by searching for a word, the way let or var lets you in other languages — a Zane declaration has no distinguishing token to grep for, and finding them all is a job for a tool that parses the grammar rather than a tool that matches strings. That is a real loss of a cheap habit, and it is the direct price of the line being as short as it is.
Every comment line carries its own marker
Comments are the one place where the width argument runs the other way. The case for /* */ is that repeating the marker is waste: the remark is one unit, so one pair of delimiters should bracket it. The language takes the wider form anyway. Zane has // and the /// documentation form, and no block comment at all — a multi-line remark is a run of single-line ones, with a marker repeated on every line.
That reading treats the repetition as a tax, and the whole decision turns on it being a feature instead. A block comment can run for hundreds of lines, and a reader does not always arrive at the top of one. They scroll into the middle of it, jump there from a search, or meet it as a hunk in a diff — and what they see is ordinary-looking text with nothing on the line to mark it as inert, because the token that made it inert is further up, possibly off the screen. Every // line answers that question about itself, from anywhere, at no distance. It is the same property the language reaches for everywhere else: a fact you can confirm by looking at the line itself rather than at its context, the local-and-structural shape the foundations story argues a reader can actually check.
Where this bites hardest is commented-out code, which is where large comment regions actually come from. A screen of code inside a /* */ reads as code — it is indented like code, it is coloured like code by anything that has lost track of the opener, and only the delimiter far above marks it as a comment. The same screen with // on every line reads as switched off at every line, with no chance of mistaking one for live.
There is a smaller, purely practical reason alongside it. Line comments leave formatting alone. A block comment’s continuation lines have to be aligned by hand against the opening token — three spaces, or whatever the opener’s width leaves — and nothing re-aligns them when the block moves or the code around it re-indents. A // line is just a line; it indents with everything else.
The cost is paid by whoever is writing rather than reading. Commenting out thirty lines takes thirty markers, and un-commenting them takes removing thirty, where a block comment is two edits total. We are leaning on the editor for that — every editor has a toggle-comment command — and leaning on tooling for a comfort the language declines to provide is a real bet, not a free one. It is the usual trade in this language’s favour: a comment is read many more times than it is written, and the read side is where we spend.
Removing pipe syntax
The last form to leave was one that had been in the language almost from the start. Pipe syntax — callableExpr|expr — existed for unnesting. Deeply nested calls are genuinely hard to read, the innermost argument sitting furthest from the name that consumes it, and a pipe let the call name come first with its argument written after it instead of wrapped inside it.
Its long survival is the less flattering half. The language shed delimiters steadily as other rules took them over — the bracket rule took [ ], ( ), and { } for separated constructs, $ went to package qualification, & to guests, # to identity, ' to the loose operators, @ to the reserved namespaces — and by the time anyone looked again, | was the last character not spoken for. That is not an argument for a feature. It is the observation that nothing else needed the token, and it kept the form alive through several rounds in which it would have lost a real contest.
Because the standing objection never went away: a pipe does not group. Parentheses hold a call and its argument together as one visual object, and nesting draws the nesting. | takes that object and cuts it in two, laying the halves side by side, so the reader reassembles the call from pieces instead of seeing it whole. That is not flattening; it is splitting, and a split reads flatter without reading better. Living with it for years never made it click.
What removed it was not that argument — that argument had been available the whole time — but the arrival of a construct that did the job properly. Once a call’s last argument could trail outside the parentheses as a { }, with no new token at all and the brace ending the statement it closes, the unnesting pressure was answered where it actually came from. The calls that hurt to read nested were the calls with a large body at the call site, and those are exactly what the trailing brace takes. Pipe had been aiming at that case all along and hitting it with a general mechanism.
So removing it cost close to nothing, which is worth saying plainly rather than inventing a loss. Small arguments go back inside the parentheses, where they group. The only loss is unnesting for an argument that is not a { } — and a call whose argument is one ordinary expression was never the call that was hard to read. In return the language gets a shorter grouping rule: pipe occupied a level in the precedence table while explicitly not being an operator, an oddity the operators story noted in passing when it listed the bounds on the loose forms. That observation stands as it was written; the level it referred to is now gone, and the loose tiers sit directly beneath the comparison operators with nothing between.
A reference document with a history
One decision left, and it is this file’s own existence. The rule until now was that the two reference documents get no story: glossary.md and syntax.md state, respectively, the spec’s terms and the shapes of its forms, and the reasoning behind any given rule was held to live with its semantics, in the topic document that owns it and the story beside that. On that reading syntax.md owns no decisions at all — it is a transcription of forms whose arguments happen elsewhere.
The chapters above are the counterexample. Which side of a declaration the type sits on is not a fact about the meaning of a declaration; no topic document owns it, and none of them would be the right place to argue it. The same is true of the width budget and the missing :, of the two orders and the swap between them, of the brackets that keep a function type from reading as a lambda, of the pipe and of the comment form. Every one of those is a decision about the surface itself, and before this file there was nowhere in the repository where any of them was written down as a decision rather than as a rule.
glossary.md keeps the exemption, and the asymmetry is not an oversight. A glossary entry’s why is a naming argument, and naming arguments already have a home: the chapter that introduces a concept is required to defend the name it gives it, so a glossary story would be a story about terms that other stories are already responsible for. Nothing plays that role for form. A > **Story:** pointer from a syntax section had nowhere to point.
The line we now draw is that a form whose reasoning is about the construct’s meaning belongs to the topic’s story — a method call’s : and ! are argued in the functions story, because the argument there is about mutation and not about punctuation — while a form whose reasoning is about the surface — order, width, what can be told apart from what — belongs here. That line is a judgement call at the margins and we will get it wrong in both directions sometimes, putting an argument here that belonged in its topic’s story or leaving one there that nobody looking at the grammar would ever find. It is still better than the arrangement it replaces, in which the second kind of reasoning had no home at all and simply went unrecorded.
intrinsic names the whole @ space
The line just drawn gets an early test in the @ sigil, where the decision is about a name on the surface and nothing about the behaviour of the named namespaces. @ marks what the compiler supplies rather than a package declares, and for most of its life it opened two namespaces, both named for their members’ nature: @primitives$ for storage and @concepts$ for the types that only ever stand in a parameter. When branching, repetition, and exiting left the grammar and became calls (the control-flow story), three operations needed a home behind the same sigil, and the name that came first to hand was @intrinsics$ — the word every compiler toolchain already uses for an operation it builds in.
It did not survive the first hard look, because the word was already describing the whole sigil. A storage primitive is exactly as much the compiler’s own as branch is; nothing about @primitives$Int is less intrinsic than an operation over it. So @intrinsics$ could only carry one of two meanings, and both were wrong. Either the namespace took the word for three operations, and the rest of the @ space was left with no name to be spoken of together; or the word covered everything behind @, and a namespace carrying it distinguished nothing, since the @ had already said as much before the name was read.
We looked at keeping the namespace and coining a fresh umbrella term for the whole space instead. That fought the language rather than the name: the everyday sense of “intrinsic”, “built into the thing itself”, is the whole-space meaning already, and a coined rival would have spent its life being explained as “what you would have called intrinsic”. So the word went to the whole space and the namespace gave it up (syntax.md §2.7): an intrinsic is anything reached through @, the @ namespaces are the intrinsic namespaces, and the operations moved to @controlflow$, named for what they are for. The rule that falls out is worth keeping for whatever joins the sigil next: a namespace is named for its members’ nature or purpose, and never for the one trait all of them share.
The definition had a casualty on its first day. Array<T, n> had always been described as the storage primitive the compiler provides, and it was written bare — the one compiler-supplied name in the language that no @ announced. Once “intrinsic” meant everything behind the sigil, that left Array either an intrinsic outside the intrinsic namespaces or an exception the definition had to carry, and neither was worth keeping for the sake of a shorter spelling. So the primitive moved to @primitives$Array<T, n> and core wraps it as Array (generics.md §8), on exactly the terms it already wrapped @primitives$Int as Int. Source did not change: examples still write Array<Int, 10000>, and the constructors that read a length off an array literal are core’s, as the constructors that read an Int off a number literal always were. What changed is that Array became a fundamental type in the plain sense the spec gives that phrase — a type core declares — and that it gained a sibling in the same namespace, @primitives$List<T>, which core wraps as List and whose own reason is told in the generics story.
The cost is that the bare word no longer names an operation. That is the sense a reader arriving from C or Rust brings, where an intrinsic is a function the compiler implements specially, so prose about the three operations has to write “control-flow intrinsic” in full, and a reader who skims past the qualifier can take a claim about the operations as a claim about every type behind @. Stretching the word over types is not new — Fortran has called its built-in types intrinsic types for decades — but it is a stretch against the more common habit, and the spec pays for it with the extra word wherever the narrower meaning is meant.
Callback lists stay inside the parentheses
The account of subscripts in the chapter on the two orders closed by admitting that nothing had ever pushed on them. The push, when it came, did not start with subscripts at all. It started with a list of callbacks.
A call’s last argument may trail when it is a { } (syntax.md §4.8), and that is what took the pipe’s job: the calls that hurt to read nested are the calls with a large body at the call site. A function that takes a list of callbacks is exactly that call, and it gets no help. Its argument is an array literal of lambdas, each with a body of its own, and the literal has to close inside the parentheses — so two levels of nesting in, the tail of the call is a pile of }, ] and ) that a reader has to count. We asked how a library author would get around it, and the answer that came to mind was to ask for the wrong type on purpose: take a map of callbacks rather than a list, because a map literal is a { } and a { } may trail. The first key type to hand, Unit, does not even work — every Unit is equal, and a repeated key replaces the entry before it (syntax.md §2.10), so such a map keeps only its last callback, and the keys would have to be counted out by hand. But the workaround exposed a problem larger than its own flaw. A map whose keys are thrown away is a list, and a literal that serves as both is a Lua table. So the question became whether lists should move into braces: { a; b; } for a list, { k, v; } for a map, the non-empty rule that settled the bare brace keeping the two apart, and [ ] left with nothing to do but subscript. That the two would share a bracket did not trouble us — a literal that is list-shaped or map-shaped and never both can still produce an Array or a Map, sharing a spelling without merging the types.
It did not survive contact with the block. The shape test that separates a map literal from a block argument reads the mark after the first expression — a , opens a map entry, a ; ends a statement (lexical.md §6.4) — and a list entry ended in ; is a statement by that test. The collision is not hypothetical: { x; } is the spec’s own example of a block argument. The non-empty rule we had counted on answers a different question, the empty brace, and says nothing about a brace holding one expression and a semicolon. The mechanism was already spoken for, and we had overlooked that fact.
One road stayed open, and it is the one worth recording, because it is buildable. A { } in value position always has a target — a block is never written anywhere but as an argument — so a brace passed to a Block parameter could be read as a block and any other as a list, parsing the contents as statements and reclassifying them afterwards. We turned it down flat. A reader of f({ fire(); }) could no longer identify the brace without finding f’s signature, which is the very information the shape test exists to put on the page. An overload set differing only by a block against a list at one position would need a ban of its own beside the passing-mode ban. And changing a parameter from one to the other would quietly turn deferred work into eager work at every call site that still compiled. Behind all three sits one objection. The argument selects the overload; a brace whose meaning the overload selects runs the dependency the other way, and a construct that can only be read once the call is resolved, in a call that can only be resolved once the construct is read, is where code stops being obvious. We did not want the meaning of a structure inferred by anything that works like overload resolution. Lists keep [ ], and the brace keeps only the readings its own contents distinguish.
That left the list with no way to trail, and the reason looked like the subscript: a [ after a call would sit where a subscript sits. So the question turned round. If the subscript is what costs lists the position, does the language need subscripts at all — why is list[i] not simply a method?
Assignment is the visible answer and not the real answer. A subscript’s result is a place, not a value (functions.md §2.9): the element’s own slot, to be read, assigned, or mutated through. A getter can hand back only a value, and that leaves it two options, neither good. It can return a copy, and then updating an element in place becomes read, modify, write back — grid[x][y].hp turns into a chain of getters and setters, each copying a whole element to change one field of it. Or it can return a guest to the element, and the memory model was built to refuse exactly that: a guest minted from a container element dangles the moment the element is popped, which is why a subscripted path is never a guest source (memory.md §2.8).
The natural patch is a borrow — a form like &T that cannot be stored. We had stood near this once before, and the 'T borrow mode was withdrawn as a sigil whose whole job was routing around a restriction we had chosen. That verdict did not settle this one, because this time the restriction is not ours to regret; the pop problem is real. The question of how long the borrow lives settled it. If it may be bound to a local, then e = list.at(3) followed by list!pop() leaves e naming a reclaimed slot, and closing that hole requires forbidding any mutation of list while e is live — aliasing analysis, the borrow checker this design was founded on not having. If it may not be bound, and lives only within the expression that produced it, it is safe, and it is exactly a subscript: a place usable for one expression, never bound and never a guest source. A borrow that can never be the declared type of a symbol, a field, or a parameter is not a type at all. It is a property of the verb that returns it, and the verb that returns a place already exists.
The call site finally made the case, rather than the declaration. a[i] tells a reader that what they are holding is a place: assignable, projected out of the container, and not theirs to keep. That is precisely the fact a reader gets wrong about containers, and a.at(i) looks like every other call in the file. The chapter on the two orders argued the declaration’s shape from the call it answers; this is the stronger half of the same argument, that the call is where the shape earns its keep. Multiple indices — tensor[x, y, z] — are a pleasant consequence of that, not the reason for it. So subscripts stay, and a borrowed type joins the features Zane weighed and does not have.
Which left the trailing position itself, and a finding that briefly reopened it. A subscript’s base must be a place, and a call result never is — CustomList()[1] is the spec’s own rejected example (syntax.md §4.5). So a [ straight after a call’s ) can never be a legal subscript; a parser tells a call’s ) from a grouping one without consulting a type, and a trailing [ ] would have changed the meaning of no existing program. It was clean, and we turned it down anyway, for two reasons that are the same objection seen twice. The first is that it would make that ban load-bearing. Today the ban on subscripting a call result is a strictness that could be relaxed — reading an element out of a returned value-type array, or indexing through a returned guest, are both relaxations a later pass might reasonably want — and once f() [x] meant a trailing list, relaxing it would have to be spelled (f())[x], a subscript told apart from a trailing argument by nothing but a pair of grouping parentheses. The second is the work a reader would need to read f() [x] at all: decide whether f()’s result could be a place, which is a question about f. And f() [x] calls f with one argument more or one fewer depending on how the bracket is read, so the bracket’s reading picks the overload while the overload’s result determines the bracket’s reading — the inversion the braces ran into, in a smaller form. We would not take it from the brace, and we did not take it from the bracket.
The cost lands where the question began. A call that takes a list of callbacks writes the list inside its parentheses, and nesting several such calls still ends in a run of closing brackets that has to be counted; the language offers nothing for that case but binding the lambdas to names before the call, which flattens the nesting at the price of a line apiece. syntax.md §4.8 now states only that an array literal is always written inside the parentheses. In exchange the episode bought a subscript that has finally been tested — against a getter, against a borrow, and against the one position it looked to be costing — and a record of three roads, braces for lists, borrowed types, and a trailing [ ], that each looked open and each ran into the same wall: the meaning of a piece of text should be settled by the text.
The instantiation forms take ^
Roaming owners arrived as a state of the memory model, and the declaration forms of syntax.md §1.1 gained nothing for them: a roaming owner could be declared only in the long form, car ^Car = Car(Int(1)). That is the doubled type the chapter on the order introduced the shorthand to remove, and it came back on a line written constantly, because a roaming owner is how an object is built before it is moved into a constructor, a ^T parameter or a field (memory.md §2.1). The settled twin of the same line had never paid it. We wanted roaming owners to be as easy to work with as settled ones, so the shorthand takes the ^ (syntax.md §1.1): car ^Car(Int(1)) is car ^Car = Car(Int(1)). Every instantiation form is the same rewrite into name VarType = expr, so every one takes it — the positional call, a named constructor, a variant case, and both braced forms: v ^Vehicle.truck(Int(4)), e ^Expr.intLit("5"), car ^Car{id; seats;}.
There is no & counterpart, because it would not make sense. A new & is minted only from a settled place (memory.md §2.8), and the value an instantiation builds is a temporary, so car &Car(Int(1)) would describe nothing. Each instantiation form has two meanings, unmarked and roaming, and the ^ follows the same rules as on the long form.
A value closed by a brace takes ., :, !, ? and ??
The question came out of the decision that a declaration ends the way a statement does. With that rule settled, we wrote Int() => Vector2{x = 0; y = 0;}.x; to check where its ; went, and found that the line did not parse at all, for a reason that had nothing to do with the ;. The compiler refused a field access, a method call, or a call written straight after any value that closes on a } — a field-constructor call, an init{ }, a map literal, a match — in any position. The ban had a real origin. ( and [ are the two tokens a postfix can open with, and they are also two tokens a statement can open with, so a match at the end of one statement followed by (y)(); on the next line read both as a call on the match and as a second statement (compiler issue 102). The spec had only half of this: lexical.md §6.3 stated that nothing continues a statement past the brace that ends it, and stated no rule for a braced value in the middle of an expression.
The ban was broader than its reason. The ambiguity came from two particular tokens, and the ban covered every postfix. A ., a :, or a ! never opens a statement — .5 is not a number in Zane, and : and ! only ever sit between a subject and a method name — so after a closing brace each of them has exactly one reading. ?, ??, and the binary operators had never been banned at all; match x { … } ?? fallback already parsed. So the line we had drawn was not between continuing a braced value and not continuing it. It was between the tokens that can begin a statement and the tokens that cannot, and the compiler had drawn it in the wrong place.
We looked at the other way out, which the compiler had already turned down: allow every postfix in the middle of an expression and forbid one only where the brace could end a statement. That needs the parser to know, while it is still inside an expression, whether the statement around it is about to end, and it gives the same text two rules depending on where it sits. Sorting by token instead needs one token of lookahead and reads the same everywhere. So a braced value takes ., :, !, ?, ??, and an operator directly, and a call or a subscript is written on the parenthesized value (syntax.md §4.9). lexical.md §6.3 now says the same from the statement’s side: a ( or a [ after the brace opens a statement of its own.
The map literal stayed outside the rule as well, for a reason of its own. A value that takes a . can stand first in its statement — Rect{w = 2; h = 3;}.w = 4; — and a map literal standing there would open the statement with a {, which lexical.md §6.3.1 already forbade so that the only braces at the start of a statement belong to a declaration. We could have let the literal take a . everywhere except first in a statement, but that is the position-dependent rule we had just turned down. So the map literal is the one braced value that takes ., :, and ! only once parenthesized, as in ({ "a", 1; }):size(). It gives up little, since a program usually binds a map to a variable before it queries the map.
A trailing argument stays outside the rule. Its brace closes a call whose ) it stands in for, and syntax.md §4.8 has that brace end the call and the statement together. That is a decision about what the trailing position is for, made separately from the ambiguity, and nothing here pressed on it.
The cost is an asymmetry a reader has to learn. Rect{w = 2; h = 3;}.w is legal and Rect{w = 2; h = 3;}(x) is not, and the reason sits in a fact about statements rather than about the value. In practice it is smaller than it looks: a subscript on a braced value was already illegal, since such a value is a temporary and a subscript needs a place (syntax.md §4.5), so the parentheses are left guarding one rare form, calling a function value that a match or a constructor produced.
A constructor call with an empty list keeps its block inside
When trailing became a property of every call (syntax.md §4.8), it reached constructor calls with everything else, and one spelling was already taken twice. TypeName() { body } is a lambda literal returning TypeName (syntax.md §3.8), and in statement position it is also a positional constructor declaration with a block body. A constructor call whose only argument is a block, written trailing, is the same tokens. An empty argument list and an empty parameter list are the same ( ), and a trailing block and a body are the same { }, so nothing inside the form distinguishes the readings. A lower-case callee names no type, which is why do() { ... } never had the problem: the casing rule separates these readings everywhere else, and here it has nothing to work with.
The compiler had first refused trailing on every constructor call, on the strength of the declaration reading. That reason reaches only statement position, so the refusal was wider than its cause. We narrowed it to the one spelling that collides: a constructor call trails its last argument like any other call, unless its ( ) would be left empty, and then the block is written inside, Threads({ poll(); });. Admitting the empty trailing form as a call would have given return Foo() { } two parses, and taking it away from the lambda literal would have broken a form the language uses everywhere a callback is passed.
The cost is one spelling a reader has to learn as an exception. worker Thread(name) { ... } trails and pool Threads() { ... } does not, and the reason lies in a collision in the grammar rather than in anything about constructors.