Values and Bindings
Design Goals
Tython prefers explicit, deterministic rules over permissive behavior.
If a construct could create ambiguity or accidental mutation, it is rejected.
Primitive Types
Built-in primitive types:
intfloatboolstrnone
Literal Forms
- Integers:
0,1,42,-7 - Floats:
0.0,3.14,-1.5 - Booleans:
true,false - None:
none - Strings:
"hello","abc"
All boolean and none literals are lowercase.
List Types and Literals
List type syntax:
int[]str[]Fish[]
List literals:
[][1, 2, 3]["a", "b"]
Mixed-type list literals are rejected:
Bindings
There are only two binding kinds:
constvar
No implicit declarations.
No let.
Declaration Syntax
Bindings may be declared in either form:
- with initializer (
name = value) - without initializer only when a type annotation is present (
name: Type)
Typed empty declarations are allowed:
Without a type annotation, empty declarations are rejected.
Mutability Rules
constcannot be reassigned.varcan be reassigned.
For const declared without initializer, the first assignment initializes it. Any later assignment is rejected.
Naming Rules
Identifiers are case-sensitive.
constnames must beUPPER_SNAKE_CASE.- Regex:
^[A-Z][A-Z0-9_]*$ varnames must besnake_case.- Regex:
^[a-z][a-z0-9_]*$ - User-defined type names must be
PascalCase. - Regex:
^[A-Z][A-Za-z0-9]*$
Reserved Words
Reserved keywords:
constvarpubrecordclasssetupinitisthisthrowscatchpanictruefalsenone
Built-in type names are reserved:
intfloatboolstrnone
Built-in value names are predeclared and cannot be redefined:
printlenrangepanicMatrix