Skip to content

Instantly share code, notes, and snippets.

@oofdere
Last active November 19, 2024 23:31
Show Gist options
  • Save oofdere/624a302041c47eb251e1cbcc8b153218 to your computer and use it in GitHub Desktop.
Save oofdere/624a302041c47eb251e1cbcc8b153218 to your computer and use it in GitHub Desktop.
what am i doing
an actor+signal based strongly typed reactivity-first language
fun main() {
// nothing is mutable, anything can be rebound, all values are Copy
// (the interpreter/compiler might choose to mutate for efficiency but this isn't exposed to users)
// signals are dynamic streams of data that can be subscribed to from anywhere
signal x = 1;
// you can derive new signals from other signals
derive y = x * 2;
// changing the type of x unbinds y, but changing the value does not
// tasks return pids upon creation
pid = Task {
// do some work on a green thread (or in the event loop when targeting JS)
print("yay");
// recieving a message
loop recv msg: Number {
msg * 2
}
// any statement can be looped
}
// tasks can be messaged
six = pid.send(3).await
// first-class cancellation
await pid.kill()
// there is no async, but await can be used to block the current thread as needed
// we <3 web apis
res = fetch("google.com").unwrap()
// variables can be rebound to a new value (or any type, really)
pid = Effect {
// effects are reactive closures that run inside a task
// this one prints every time x or y changes
print("{x} * 2 = {y}")
}
:ok // first class atoms
// destructured pattern matching
// panics if response is not :ok
{ response: :ok, body: String } = fetch("").await.unwrap()
// this does the same thing, but assuming a result is returned instead of a struct
Ok<{body}> = fetch("").await
// and this is just sugar for the following:
body = {
// makes the fetch call
fetch("")
// await just waits for response to hit the inbox
recv res.unwrap()
// last statement in a block is always a return
}
// you can implement a function multiple times with different sets of inputs and outputs
// kinda like elixir but types are used instead of arity
fun fetch(url) -> {response: Atom, body: string}
fun fetch(url) -> Result<T, E>
// you can also do this with traits
impl Into for Example {
// no need for borrows when everything is copy and sync and immutable >:3
fun into(self) -> String {}
fun into(self) -> Number {}
fun into(self) -> Bool {}
}
// you can also use match blocks
match { fetch("").await.unwrap() } {
{ code: 200, body } => Ok(body)
code => Err(code)
} // this block is exhaustive because all responses include a code
// array
arr = [1, 2, 3, 4]
// array destr
[head | tail] = arr
// usable enums
// just imagine a rust enum
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment