backup commit of notes so far

This commit is contained in:
2023-05-14 20:35:31 +01:00
parent 6a381c5b57
commit 33413b2b0f
34 changed files with 1109 additions and 421 deletions

15
examples/lite/fn.orc Normal file
View File

@@ -0,0 +1,15 @@
export Y := \f.(\x.f (x x))(\x.f (x x))
export loop $r on (...$parameters) with ...$tail =0x5p512=> Y (\$r.
bind_names (...$parameters) (...$tail)
) ...$parameters
-- bind each of the names in the first argument as a parameter for the second argument
bind_names ($name ..$rest) $payload =0x2p1000=> \$name. bind_names (..$rest) $payload
bind_names () (...$payload) =0x1p1000=> ...$payload
export ...$prefix $ ...$suffix:1 =0x1p130=> ...$prefix (...$suffix)
export ...$prefix |> $fn ..$suffix:1 =0x2p130=> $fn (...$prefix) ..$suffix
export (...$argv) => ...$body =0x2p512=> (bind_names (...$argv) (...$body))
$name => ...$body =0x1p512=> (\$name. ...$body)

41
examples/lite/list.orc Normal file
View File

@@ -0,0 +1,41 @@
import option
import super::fn::*
pair := \a.\b. \f. f a b
-- Constructors
export cons := \hd.\tl. option::some (pair hd tl)
export end := option::none
export pop := \list.\default.\f.list default \cons.cons f
-- Operators
export reduce := \list.\acc.\f. (
loop r on (list acc) with
pop list acc \head.\tail. r tail (f acc head)
)
export map := \list.\f. (
loop r on (list) with
pop list end \head.\tail. cons (f head) (r tail)
)
export skip := \list.\n. (
loop r on (list n) with
if n == 0 then list
else pop list end \head.\tail. r tail (n - 1)
)
export take := \list.\n. (
loop r on (list n) with
if n == 0 then end
else pop list end \head.\tail. cons head $ r tail $ n - 1
)
new[...$item, ...$rest:1] =0x2p333=> (cons (...$item) new[...$rest])
new[...$end] =0x1p333=> (cons (...$end) end)
new[] =0x1p333=> end
export ::(new)

View File

@@ -1,9 +1,10 @@
import prelude::*
import std::(parse_float, to_string)
import std::(readline, print)
import std::(readline, print, debug)
import std::(concatenate)
import super::list
import fn::*
export main := do{
--[ export main := do{
cps data = readline;
let a = parse_float data;
cps op = readline;
@@ -19,6 +20,35 @@ export main := do{
);
cps print (to_string result ++ "\n");
0
} ]--
export main := do{
let foo = list::new[1, 2, 3, 4, 5, 6];
let bar = list::map foo n => n * 2;
let sum = bar
|> list::skip 2
|> list::take 3
|> list::reduce 0 (a b) => a + b;
cps print $ to_string sum ++ "\n";
0
}
-- export main := 1 do { 1 ; 2 } 3
--[
export main := do{
let n = 1;
let acc = 1;
loop r on (n acc) with (
if n == 5
then print acc
else r (n + 1) (acc * 2)
)
}
]--
--[
export main := do{
let n = 1;
loop r on (n) with (
debug r
)
}
]--

6
examples/lite/option.orc Normal file
View File

@@ -0,0 +1,6 @@
export some := \v. \d.\f. f v
export none := \d.\f. d
export map := \option.\f. option none f
export flatten := \option. option none \opt. opt
export flatmap := \option.\f. option none \opt. map opt f