Skip to content

Instantly share code, notes, and snippets.

@wooosh
Last active August 11, 2020 18:43
Show Gist options
  • Save wooosh/a90fbe11b72fc121c520bcfd0c56cafc to your computer and use it in GitHub Desktop.
Save wooosh/a90fbe11b72fc121c520bcfd0c56cafc to your computer and use it in GitHub Desktop.
Zest Language Samples

Zest Language Samples

Types

Built-In Types (excludes standard library)

Types
Unsigned uint, u8, u16, u32, u64
Signed sint, s8, s16, s32, s64
Floats TODO

Arrays

Structures

// TODO: defaults
// TODO: tagging
// TODO: setters
structure greeter {
  sint num_greeted
  string greeting : getter (greeter self) => {
    return "Hello! You're the " + string(self.num_greeted) + " person to be greeted"
  }
}

Unions

Type Inspection

  • tags
  • struct.for_each_member

Operators

Functions

fn add_two_s64(sint a, sint b) -> sint {
  return a + b
}

// returns a function that returns a string
fn create_greeter_fn(string name) -> fn() -> string {
  // lambda synax
  return () => "Hello " + name + "!"
}

// adds any type with itself that implements the + trait
fn add_two<T>(T a, T b) -> T {
  return a + b
}

Variable Definitions

let a sint
let b sint = 100
const c sint = 100 // MUST be defined at compile time

Variable Tagging

Traits

Imports

// imports must be at the start of the file, though comments are allowed before imports
import module_a
import module_b.module_ba
import module_c as mod_c
from module_d import print_d, is_d
import module_e
import module_item

fn example_a() -> module_item:item {
  module_a:print_a()
  module_b:module_b:print_ba()
  mod_c:print_c()
  return module_item:make_item()
}
fn example_b() {
  use module_a // applies to the current block scope
  print_a()
  use module_e {
    print_e()
  }
}

// types and functions are exported with pub
pub fn my_fn() {}
pub struct my_struct {}
pub union {}

Basic Control Structures

if

if condition {
  call_function()
}
// parens are required if you don't use curly braces
if (condition) call_function()

if (condition1) {
  func1()
} elif (condition2) {
  func2()
} else {
  func3()
}

While & Do While

let counter uint
while counter != 10 {
  do_something()
  counter++
}

// parens are required if you don't use curly braces
while (get_status() == status.failed) retry()

For

Match

Memory Management

Package Manager

Example Programs

Things that need work

  • Type inspection
  • Lambda syntax
  • Dynamic imports
  • Empty headings
  • Method of accessing unexported features
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment