From 9748e95027af7820e6d9f08eb20b0901fdedfa2a Mon Sep 17 00:00:00 2001 From: Cody Date: Mon, 26 Jun 2023 23:53:44 -0500 Subject: [PATCH] Delete random examples --- examples/features.sloth | 42 --------------- examples/fib.sloth | 90 -------------------------------- examples/fib_gen.sloth | 14 ----- examples/fib_rec.sloth | 7 --- examples/hello.sloth | 2 +- examples/hello2.sloth | 11 ---- examples/ui.sloth | 56 -------------------- examples/webserver.sloth | 108 --------------------------------------- 8 files changed, 1 insertion(+), 329 deletions(-) delete mode 100644 examples/features.sloth delete mode 100644 examples/fib.sloth delete mode 100644 examples/fib_gen.sloth delete mode 100644 examples/fib_rec.sloth delete mode 100644 examples/hello2.sloth delete mode 100644 examples/ui.sloth delete mode 100644 examples/webserver.sloth diff --git a/examples/features.sloth b/examples/features.sloth deleted file mode 100644 index 26be73c..0000000 --- a/examples/features.sloth +++ /dev/null @@ -1,42 +0,0 @@ -fn calories(input) { - var elves = [] - var current = 0 - - for line in input.lines() { - if line.empty() { - elves.append(current) - current = 0 - continue - } - - current += line as!! int - } - - elves.sort() - elves.reverse() - - return elves[0..3].sum() -} - -fn fib(x: int) { - if x < 2 { - return x - } - - return fib(x - 1) + fib (x - 2) -} - -fn codes(input: String): List { - val chars = input.chars() - .windowed(4) - .map(it -> it as Set) - .filter(-> $0.len() == 4) - .map(it -> it.join()) - return chars -} - -## Will convert celsius to fahrenheit -fn fahrenheit(celsius) { - return 32.0 + celsius * 1.8 -} - diff --git a/examples/fib.sloth b/examples/fib.sloth deleted file mode 100644 index 9b0cee9..0000000 --- a/examples/fib.sloth +++ /dev/null @@ -1,90 +0,0 @@ -fn fib(n: i32): i32 { - val msg = if (n == 0) "No points" else "Some points" - val msg = if n == 0 { "No points" } else { "Some points" } - val msg = if n == 0: "No points" else: "Some points" - - if n == 0 || n == 1 { - return n; - } - - var grandparent = 0; - var parent = 1; - var me = 0; - - for i in 0..n-1 { - me = parent + grandparent; - grandparent = parent; - parent = me; - } - - return me; -} - -pub type Button = { - pub x: i32, - pub y: i32, - text: String, -} - -impl Button { - fn init(text) { - return Self( - x: 50, - y: 150, - text, # Pass in text - ) - } -} - -impl Constructor for Button { - fn init(text) { - Self( - x: 50, - y: 150, - text, # Pass in text - ) - } -} - -Button::init("Hello") -Button("Hello") - -print(fib(0)); -print(fib(1)); -print(fib(2)); -print(fib(3)); -print(fib(4)); -print(fib(5)); - -# Inferred as List -val nums = read("input.txt") - .lines() - .filter(-> /$[0-9]+^/ in $0) - .collect() - -fn T <- From = List collect(self): T { - -} - -fn collect(self): 'a -where - 'a : From, # Type Constraints - 'a = List, # Generic Defaults - 'a : From = List, # Combined -{ - # -} - -# This following code should -fn add(lhs, rhs) { - return lhs + rhs; -} - -# Ideally infer to -fn add(lhs: 'a, rhs: 'b): 'c -where - 'a : Add<'b, 'c>, - 'b = 'a, -{ - return lhs + rhs; -} diff --git a/examples/fib_gen.sloth b/examples/fib_gen.sloth deleted file mode 100644 index dd9e08f..0000000 --- a/examples/fib_gen.sloth +++ /dev/null @@ -1,14 +0,0 @@ -fn fib(n: i32) -> i32 { - match n { - 0 | 1 => n, - _ => fib(n - 1) + fib(n - 2), - } -} - -generator fn fib_sequence(range: Range) -> i32 { - for n in range { - yield fib(n); - } -} - -print(fib_sequence(0..20).join(", ")) diff --git a/examples/fib_rec.sloth b/examples/fib_rec.sloth deleted file mode 100644 index 306bcdf..0000000 --- a/examples/fib_rec.sloth +++ /dev/null @@ -1,7 +0,0 @@ -## Calculate a specific number in the fibonacci sequence -fn fib(n: i32) -> i32 { - match n { - 0 | 1 => n, - _ => fib(n - 1) + fib(n - 2), - } -} diff --git a/examples/hello.sloth b/examples/hello.sloth index 13415a9..6f56632 100644 --- a/examples/hello.sloth +++ b/examples/hello.sloth @@ -1,6 +1,6 @@ foreign fn print(x: String) Void; fn main() Int { - print("gaming\n"); + print("Hello World\n"); return 0; } diff --git a/examples/hello2.sloth b/examples/hello2.sloth deleted file mode 100644 index 589d969..0000000 --- a/examples/hello2.sloth +++ /dev/null @@ -1,11 +0,0 @@ -fn example() {} - -fn main() { - var i: Int = 10; - var j: Int = 1.0 - 1; - while i > j { - i = i - 1; - } - example(i); -} - diff --git a/examples/ui.sloth b/examples/ui.sloth deleted file mode 100644 index 2f69825..0000000 --- a/examples/ui.sloth +++ /dev/null @@ -1,56 +0,0 @@ -use extern "ui" - -use ui::components::Button; -use ui::components::Label; -use ui::components::FlexView; - -type Action = - | Increment - | Decrement - -fn update(state, message) { - match message { - Action::Increment -> state + 1, - Action::Decrement -> state - 1, - } -} - -fn render(state, dispatch) { - return FlexView([ - Button("-", action: -> dispatch(Action::Decrement)), - Label(state), - Button("+", action: -> dispatch(Action::Increment)), - - FlexView( - height: 500, - width: 220, - body: [ - Label("List 1"), - Label("List 2"), - Label("List 3"), - ], - ) - - Button( - width: 100, - height: 20, - action: -> (), - body: Label("Sign up"), - ) - ]) -} - -fn app() { - # Creating our state - val state = 0 - - # Creating our app - val app = ui::App( - state, - on_update: update, - on_render: render, - ) - - # Starting our app - app.start() -} diff --git a/examples/webserver.sloth b/examples/webserver.sloth deleted file mode 100644 index abbead3..0000000 --- a/examples/webserver.sloth +++ /dev/null @@ -1,108 +0,0 @@ -# Include the external dependency itself as a module named "slow_api" -use extern "slowapi" as slow_api; - -# Use some things from the "slow_api" module -use std::serde::Serializable; -use std::serde::format::Json; - -use slow_api::{SlowAPI, Method}; - -# Construct a slow API server -val server = SlowApi(); - -type Person derives Serializable = { - name: String, - age: Option -}; - -fn hello_route( - name: Argument, - age: Argument>, -) -> Json { - Person { name, age } -} - -# Start the server -server - .route(Method::GET, "/hello", hello_route) - .start("0.0.0.0:8000"); -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -### -type Poggies; - -trait Constructor<..T> { - fn new(..T) -> Self; -} - -impl Constructor<> for Poggies { - fn new() -> Self { - # - } -} - -impl> Default for T { - fn default() -> Self { - Self::new() - } -} - -### -type Person = { - name: String, - age: i32, -}; - -type Person derives Serialize, Deserialize = { - name: String, - age: i32, -}; - -@route::get("/teacup") # vvvvvv - Requires T to implement Serialize -fn teacup_route() -> Response { - Response(418, Person { - name: "Cody Q", - age: 17, - }) -}