Skip to content

Commit

Permalink
Adapting to new List type (part 19).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed May 16, 2024
1 parent 2a7e9f0 commit 46c9158
Show file tree
Hide file tree
Showing 23 changed files with 212 additions and 531 deletions.
37 changes: 17 additions & 20 deletions stdlib/source/library/lux/compiler/meta/cache/dependency/module.lux
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
["[0]" text]
[collection
["[0]" list (.use "[1]#[0]" functor mix)]
["[0]" stack (.use "[1]#[0]" functor mix)]
["[0]" dictionary (.only Dictionary)]
["[0]" set (.only Set)]]]]]
[////
Expand All @@ -42,21 +41,20 @@

(the .public modules
(-> Graph
(Stack descriptor.Module))
(|>> dictionary.keys
list.as_stack))
(List descriptor.Module))
dictionary.keys)

(every .public Dependency
(Record
[#module descriptor.Module
#imports Ancestry]))

(the .public graph
(-> (Stack Dependency)
(-> (List Dependency)
Graph)
(stack#mix (function (_ [module imports] graph)
(dictionary.has module imports graph))
..empty))
(list#mix (function (_ [module imports] graph)
(dictionary.has module imports graph))
..empty))

(the (ancestry archive)
(-> Archive
Expand All @@ -75,9 +73,9 @@
ancestry (memo.open memo)]
(list#mix (function (_ module memory)
(if (dictionary.key? memory module)
memory
(let [[memory _] (ancestry [memory module])]
memory)))
memory
(let [[memory _] (ancestry [memory module])]
memory)))
..empty
(archive.archived archive))))

Expand All @@ -90,7 +88,7 @@
(set.member? target_ancestry source)))

(every .public (Order it)
(Stack [descriptor.Module [module.ID (archive.Entry it)]]))
(List [descriptor.Module [module.ID (archive.Entry it)]]))

(the .public (load_order key archive)
(for_any (_ it)
Expand All @@ -100,11 +98,10 @@
(|> ancestry
dictionary.keys
(list.sorted (..dependency? ancestry))
list.as_stack
(stack.each' try.monad
(function (_ module)
(do try.monad
[module_id (archive.id module archive)
entry (archive.find module archive)
document (document.marked? key (its [archive.#module module.#document] entry))]
(in [module [module_id (has [archive.#module module.#document] document entry)]])))))))
(list.each' try.monad
(function (_ module)
(do try.monad
[module_id (archive.id module archive)
entry (archive.find module archive)
document (document.marked? key (its [archive.#module module.#document] entry))]
(in [module [module_id (has [archive.#module module.#document] document entry)]])))))))
23 changes: 11 additions & 12 deletions stdlib/source/library/lux/compiler/meta/cache/purge.lux
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,22 @@
Purge)
(|>> (list.all (function (_ [valid? module_name @module _])
(if valid?
{.#None}
{.#Some [module_name @module]})))
{.#None}
{.#Some [module_name @module]})))
(dictionary.of_list text.hash)))

(the .public (purge caches load_order)
(the .public (purge caches)
(-> (List Cache) (dependency.Order Any)
Purge)
(list#mix (function (_ [module_name [@module entry]] purge)
(let [purged? (is (Predicate descriptor.Module)
(dictionary.key? purge))]
(if (purged? module_name)
purge
(if (|> entry
(its [archive.#module module.#descriptor descriptor.#references])
set.as_list
(list.any? purged?))
(dictionary.has module_name @module purge)
purge))))
(..initial caches)
(list.of_stack load_order)))
purge
(if (|> entry
(its [archive.#module module.#descriptor descriptor.#references])
set.as_list
(list.any? purged?))
(dictionary.has module_name @module purge)
purge))))
(..initial caches)))
53 changes: 19 additions & 34 deletions stdlib/source/library/lux/control/maybe.lux
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

(.using
[library
[lux (.except stack with when or)
[lux (.except with when or macro)
[abstract
[monoid (.only Monoid)]
[equivalence (.only Equivalence)]
[hash (.only Hash)]
[functor (.only Functor)]
[monad (.only Monad do)]]]])

(the template#macro (.in_module# .prelude .template#macro))
(the macro (.in_module# .prelude .template#macro))

... (every (Maybe it)
... (Variant
Expand Down Expand Up @@ -130,33 +130,20 @@
(by monad each (by ..monad in)))

(the .public else
(template#macro
(_ ,else ,maybe)
[(.when ,maybe
{.#Some 'it}
'it
(macro (_ ,else ,maybe)
[(.when ,maybe
{.#Some 'it}
'it

{.#None}
,else)]))
{.#None}
,else)]))

(the .public trusted
(for_any (_ it)
(-> (Maybe it)
it))
(|>> (..else (undefined))))

(the .public (stack value)
(for_any (_ it)
(-> (Maybe it)
(Stack it)))
(.when value
{.#Some value}
(.stack value)

... {.#None}
_
(.stack)))

(the .public (as_list value)
(for_any (_ it)
(-> (Maybe it)
Expand All @@ -169,18 +156,16 @@
(list)))

(the .public when
(template#macro
(_ <test> <then>)
[(if <test>
<then>
{.#None})]))
(macro (_ <test> <then>)
[(if <test>
<then>
{.#None})]))

(the .public or
(template#macro
(_ ,left ,right)
[(.when ,left
{.#Some 'it}
{.#Some 'it}

{.#None}
,right)]))
(macro (_ ,left ,right)
[(.when ,left
{.#Some 'it}
{.#Some 'it}

{.#None}
,right)]))
25 changes: 12 additions & 13 deletions stdlib/source/library/lux/control/pattern.lux
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
["[0]" bit]
["[0]" text]
[collection
[stack
["[0]" list (.only)
["[0]" property]]]]
[math
[number
Expand Down Expand Up @@ -226,18 +226,17 @@
(the .public (item pattern)
(for_any (_ it number outer inner value)
(-> (Pattern number it outer inner value)
(Pattern number (Stack it) outer inner value)))
(Pattern number (List it) outer inner value)))
(let [[number match] pattern]
[number
(function (again input)
(.when input
{.#Empty}
..failure

{.#Top head tail}
(..try (match head)
(function (_ then else stack)
((again tail) then else stack)))))]))
(function (_ input)
(let [size (.list_size# input)]
(loop (item [address 0])
(if (natural.< size address)
(..try (match (.list_item# address input))
(function (_ then else stack)
((item (++ address)) then else stack)))
..failure))))]))

(every .public (Static it)
(for_any (_ value arity)
Expand Down Expand Up @@ -294,14 +293,14 @@

(the .public (has key)
(-> Text
(Dynamic property.Stack))
(Dynamic property.List))
(..item (..pair (..text key)
..variable)))

(the .public (first predicate)
(for_any (_ it)
(-> (Predicate it)
(Dynamic Stack it)))
(Dynamic List it)))
(..item (..and (..is predicate)
..variable)))

Expand Down
32 changes: 18 additions & 14 deletions stdlib/source/library/lux/data/collection/list.lux
Original file line number Diff line number Diff line change
Expand Up @@ -367,20 +367,6 @@
{.#Some default}
(of_full_array default it)))

(the .public (all check it)
(for_any (_ _0 _1)
(-> (-> _0 (Maybe _1)) (List _0)
(List _1)))
(..mix (function (_ item it)
(.when (check item)
{.#Some item}
(by ..monoid composite it (list item))

{.#None}
it))
..empty
it))

(the .public (zipped_2 _0 _1)
(for_any (_ _0 _1)
(-> (List _0) (List _1)
Expand Down Expand Up @@ -462,6 +448,24 @@
..abstraction
[state]))))))

(the .public (all value it)
(for_any (_ _0 _1)
(-> (-> _0 (Maybe _1))
(-> (List _0)
(List _1))))
(let [size (.list_size# it)
[_ it] (dynamic (function (item address)
(if (n.< size address)
(when (value (.list_item# address it))
{.#Some item}
{.#Some [(++ address) item]}

none
(item (++ address)))
{.#None}))
0)]
it))

(with_template' [,name ,identity ,composite]
[(the .public (,name ? it)
(for_any (_ it)
Expand Down
17 changes: 0 additions & 17 deletions stdlib/source/library/lux/data/collection/sequence.lux
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
[collection
["[0]" list (.use "[1]#[0]" mix functor monoid)
["?[1]" \\projection]]
["[0]" stack (.use "[1]#[0]" mix functor monoid)]
["[0]" array
["[1]" \\unsafe (.only Array)]]]]
[math
Expand Down Expand Up @@ -203,22 +202,6 @@
{.#Some})
)))

(the (node#stack node)
(for_any (_ it)
(-> (Node it)
(Stack it)))
(when node
{#Base base}
(array.as_stack {.#None} base)

{#Hierarchy hierarchy}
(|> hierarchy
(array.as_stack {.#None})
stack.reversed
(stack#mix (function (_ sub acc)
(stack#composite (node#stack sub) acc))
{.#Empty}))))

(every .public (Sequence it)
(Record
[#level Level
Expand Down
Loading

0 comments on commit 46c9158

Please sign in to comment.