STL rework

- fixed lots of bugs
- overlay libraries work correctly and reliably
- the STL is an overlay library
- examples updated
This commit is contained in:
2023-06-17 21:12:23 +01:00
parent 5bb8a12fc2
commit aebbf51228
91 changed files with 1444 additions and 1395 deletions

47
src/stl/list.orc Normal file
View File

@@ -0,0 +1,47 @@
import super::(option, fn::*, bool::*, known::*, num::*,)
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
)
export get := \list.\n. (
loop r on (list n) with
pop list option::none \head.\tail.
if n == 0 then option::some head
else r tail (n - 1)
)
new[...$item, ...$rest:1] =0x2p84=> (cons (...$item) new[...$rest])
new[...$end] =0x1p84=> (cons (...$end) end)
new[] =0x1p84=> end
export ::(new)