Almost Alpha

Massive improvements across the board.

One day I'll adopt incremental commits.
This commit is contained in:
2024-02-23 23:59:24 +00:00
parent c279301583
commit ed0d64d52e
147 changed files with 4121 additions and 4203 deletions

View File

@@ -1,14 +1,12 @@
import std::(to_float, to_string, panic, string::char_at)
import std::(panic, string::char_at)
import std::conv::(to_float, to_string)
export const main := do{
cps print "left operand: ";
cps data = readln;
cps data = prompt "left operand: ";
let a = to_float data;
cps print "operator: ";
cps op = readln;
cps println ("you selected \"" ++ op ++ "\"");
cps print "right operand: ";
cps data = readln;
cps op = prompt "operator: ";
cps println "you selected \"${op}\"";
cps data = prompt "right operand: ";
let b = to_float data;
let result = (
if op == "+" then a + b
@@ -17,6 +15,6 @@ export const main := do{
else if op == "/" then a / b
else (panic "Unsupported operation")
);
cps println ("Result: " ++ to_string result);
0
cps println "Result: ${result}";
exit_status::success
}

View File

@@ -1,46 +1,35 @@
import system::(io, fs, async)
import std::(to_string, to_uint, inspect)
import std::(conv::(to_string, to_uint), inspect)
--[
const folder_view_old := \path. do{
cps println $ "Contents of " ++ fs::os_print path;
const folder_view := \path. do cps {
cps println $ "Contents of ${path}";
cps entries = async::block_on $ fs::read_dir path;
cps list::enumerate entries
|> list::map ((t[id, t[name, is_dir]]) =>
println $ to_string id ++ ": " ++ fs::os_print name ++ if is_dir then "/" else ""
println $ "${id}: ${name}" ++ if is_dir then "/" else ""
)
|> list::chain;
cps print "select an entry, or .. to move up: ";
cps choice = readln;
if (choice == "..") then do {
let parent_path = fs::pop_path path
|> option::assume
|> tuple::pick 0 2;
next parent_path
} else do {
cps choice = prompt "select an entry, or .. to move up: ";
cps new_path = if choice == ".." then do cps {
let t[parent_path, _] = fs::pop_path path
|> option::assume;
cps pass parent_path;
} else do cps {
let t[subname, is_dir] = to_uint choice
|> (list::get entries)
|> option::assume;
let subpath = fs::join_paths path subname;
if is_dir then next subpath
else do {
cps if is_dir then pass subpath else do cps {
cps file = async::block_on $ fs::read_file subpath;
cps contents = async::block_on $ io::read_string file;
cps println contents;
next path
}
}
}
]--
const folder_view := \path. do cps {
cps println $ "Contents of " ++ fs::os_print path;
cps entries = async::block_on $ fs::read_dir path;
let t[name, is_dir] = option::assume $ list::get entries 0;
cps println $ to_string name ++ " " ++ fs::os_print is_dir
cps _ = prompt "Hit Enter to return to the parent directory: ";
cps pass path;
};
};
cps pass new_path;
}
const main := loop_over (path = fs::cwd) {
cps folder_view path;
cps path = folder_view path;
}

View File

@@ -1,10 +1 @@
import std::exit_status
import std::conv
import std::number
import std::tuple
import std::list
const main := match t["set", "foo", 1] {
t[= "set", key, val] =>
$"Setting ${ key ++ $"${1 + 1}" } to ${val}"
}
const main := println "Hello World!" exit_status::success

View File

@@ -9,5 +9,5 @@ export const main := do{
|> list::reduce ((a, b) => a + b)
|> option::assume;
cps println $ to_string sum;
0
exit_status::success
}

View File

@@ -1,4 +1,4 @@
import std::to_string
import std::conv::to_string
export const main := do{
let foo = map::new[
@@ -10,5 +10,5 @@ export const main := do{
let num = map::get foo "bar"
|> option::assume;
cps println $ to_string num;
0
exit_status::success
}

View File

@@ -15,9 +15,9 @@ const bar := map::new[
]
const test2 := match bar {
map::having ["is_alive" = true, "greeting" = foo] => foo
map::having ["is_alive" = true, "greeting" = hello, "name" = name] => hello
}
const tests := test2 ++ ", " ++ test1
const tests := "${test2}, ${test1}"
const main := conv::to_string bar

View File

@@ -0,0 +1,23 @@
protocol animal (
const noise := vcall "noise"
)
type dog (
const new := \name. wrap name
impl super::animal := map::new [
"noise" = \dog. "${dog}: Woof!"
]
)
type cat (
const new := wrap 0
impl super::animal := map::new [
"noise" = \_. "a cat: Mew!"
]
)
const main := do {
list::new [dog::new "Pavlov", cat::new]
|> list::map (\a. println $ animal::noise a)
|> list::chain exit_status::success
}