Last active
May 3, 2022 23:39
-
-
Save lmumar/3b7a231f727e8e5ca2fbca4626f495e3 to your computer and use it in GitHub Desktop.
Informal design document for pythia programming language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Point = struct { | |
x, y: float | |
} | |
type PointPtr = ^Point | |
p : PointPtr | |
p = new Point | |
p.x = 100 | |
p.y = 200 | |
free p | |
' Example of a function that does not return anything | |
fn swap(a, b : ^int) { | |
tmp := n^ | |
n^ = b^ | |
b^ = tmp | |
} | |
a := 100 | |
b := 200 | |
swap(@a, @b) | |
' Example of a function that does return something | |
fn add(a, b: int) : int { | |
a + b | |
} | |
type Node = struct { | |
owned_a, owned_b: uniq ^Node | |
} | |
node := new Node | |
node.owned_a = new Node | |
node.owned_b = new Node | |
' this will delete both owned_a & owned_b | |
' since it was marked as uniq | |
free node | |
node := new Node | |
owned_a := new Node | |
owned_b := new Node | |
' this will trigger an error | |
node.owned_a = owned_a | |
' you have to have ownership of pointer to node since | |
' owned_a, owned_b are marked uniq in node struct | |
node.owned_a <- owned_a | |
node.owned_b <- owned_b | |
' no longer accessible will trigger an error | |
owned_a | |
type Node = struct { | |
a, b: ^Node | |
} | |
node := new Node | |
node.a = node | |
node.b = node | |
' this will not delete a & b | |
' since it was not marked as uniq | |
free node | |
** operators ** | |
' Ternary operators | |
a := 0 | |
b := 100 | |
c := iif(a > b, 10, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment