Language overview
Pyking reads like Python. This page covers the main places where it differs. Every example is a whole program: press ▶ to run it, or edit it first. Each one runs on its own, so a name defined in one example is not visible in the next.
Bindings and variables
= binds a name to a value, and that binding never changes. A variable
that changes is declared with var and updated with :=.
Updating a name that was bound with = is a compile-time error. This
example is meant to be refused:
Functions and types
Annotations are optional. Where a function has none, the checker infers
its most general type, so twice below works with any function whose
argument and result have the same type.
A function’s value is its last expression, or what it returns. A body
of one expression can go on the header’s line, as above.
Control flow
if is a statement, and also an expression written
if c then a else b. while loops while its condition holds.
loop carries values from one turn to the next. Each turn ends with the
next values, and break stops the loop. The loop’s value is what it
carried last.
Lists, tuples and pattern matching
match takes values apart. A list pattern [first] ++ rest matches a
non-empty list, and a tuple is taken apart with =.
Recursion
A call in tail position does not use up stack space, so a recursive function can run for as long as a loop.
Modules and the standard library
A program uses a module with import. The standard library
comes with Pyking. This example reads one line of standard input, which is
filled in above the code:
Next steps
- Try your own programs in the playground.
- Browse the libraries.
pyk replstarts an interactive session in a terminal.