What's Changed
Unified Declaration Syntax via Tuples
This update introduces a paradigm shift in the language's syntax by leveraging Tuples to unify the definitions of functions, types, and variables. By treating everything—from parameters to standalone types—as a tuple, we have achieved a truly "orthopedic" language design where data structures and logic share a single DNA.
1. The Core Philosophy: "Everything is a Tuple"
The cornerstone of this update is the realization that a type, a named field, and a collection of fields are all just variations of a tuple. Specifically, the following are semantically identical:
T(a raw type)(T)(a single-element tuple)(name T)(a named single-element tuple)
In this version, $T \equiv (T) \equiv (name\ T)$. Whether you are defining a single integer or a complex set of parameters, you are working within the same tuple-based framework.
2. Functions as Tuple Transformations
Under this unified model, a function is no longer a special construct with its own unique grammar. Instead, a function is defined as a transformation from one tuple to another.
- Mapping: $Tuple_{in} \to Tuple_{out}$
-
The Unit Tuple: If a function has no parameters or no return values, it simply interacts with the Empty Tuple
().
3. Unified Syntax in Action
By standardizing on tuples, the syntax for functions, types, and variables becomes perfectly symmetrical. Notice how the "shape" of the data remains constant across different keywords:
func run (timeout, maxRetries int, debug bool) (code int, err error)
type Config (timeout, maxRetries int, debug bool)
var cfg (timeout, maxRetries int, debug bool)
var result (code int, err error)Release Notes
This is the most significant update since XGo was renamed.
XGo MiniSpec has removed StructType and CompositeLit. This means the T{...} syntax is no longer part of the recommended grammar set — this includes []T{...}, map[K]V{...}, NamedT{...}, and so on. These have been replaced by TupleType and TupleLit.
features:
- Tuple Types (#2538) by @xushiwei @xgopilot[bot] in #2539 #2547 #2548 #2549 #2550 #2551 #2552 #2553 #2554 #2555 #2556 #2557
feature specs:
- Tuple Types by @xushiwei @xgopilot[bot] in #2561
- Keyword Arguments by @xushiwei @xgopilot[bot] in #2564
demos:
- TupleTypes and TupleLits: demo/tupletype
type Point (x, y int)
pt := Point(2, 3)
echo pt.x, pt.y
pt = (100, 200)
echo pt
pt2 := Point(y = 5, x = 3)
echo pt2- Keyword Arguments and Tuples: demo/kwargs
type Config (timeout, maxRetries int, debug bool)
func run(task int, cfg Config?) {
if cfg.timeout == 0 {
cfg.timeout = 30
}
if cfg.maxRetries == 0 {
cfg.maxRetries = 3
}
echo "timeout:", cfg.timeout, "maxRetries:", cfg.maxRetries, "debug:", cfg.debug
echo "task:", task
}
run 100, timeout = 60, maxRetries = 5
run 200deps:
Full Changelog: v1.6.0...v1.6.1