Skip to content

Commit

Permalink
Adapting to new List type (part 33).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Jun 6, 2024
1 parent 838395f commit cd5a8e1
Show file tree
Hide file tree
Showing 19 changed files with 536 additions and 531 deletions.
555 changes: 278 additions & 277 deletions stdlib/source/library/lux.lux

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion stdlib/source/library/lux/compiler/language/lux/syntax.lux
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@

(..failure source' error)
(if (same? <close> error)
(..success source' {<tag> where (list.of_stack (stack.reversed stack))})
(..success source' {<tag> where (list.reversed (list.of_stack stack))})
(..failure source' error)))))]

... Form and tuple syntax is mostly the same, differing only in the
Expand Down
2 changes: 1 addition & 1 deletion stdlib/source/library/lux/compiler/meta/packager.lux
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
(every .public Packager
(-> (Dictionary file.Path Binary) Archive (Maybe unit.ID)
(Try (Either Binary
(Stack [Text Binary])))))
(List [Text Binary])))))

(every .public Order
(List [module.ID (List artifact.ID)]))
Expand Down
28 changes: 15 additions & 13 deletions stdlib/source/library/lux/compiler/meta/packager/ruby.lux
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
[collection
["[0]" sequence]
["[0]" list (.use "[1]#[0]" functor mix monoid)]
["[0]" stack (.use "[1]#[0]" functor mix)]
["[0]" dictionary (.only Dictionary)]
["[0]" set (.only Set)]]]
[math
Expand Down Expand Up @@ -78,14 +77,16 @@
(in {.#Some bundle})))))

(the module_file
(-> module.ID file.Path)
(|>> %.natural (text.suffix ".rb")))
(-> module.ID
file.Path)
(|>> %.natural
(text.suffix ".rb")))

(the (write_module mapping necessary_dependencies [module [module_id entry]] sink)
(-> (Dictionary descriptor.Module module.ID) (Set unit.ID)
[descriptor.Module [module.ID (archive.Entry .Module)]]
(Stack [module.ID [Text Binary]])
(Try (Stack [module.ID [Text Binary]])))
(-> (List [module.ID [Text Binary]])
(Try (List [module.ID [Text Binary]]))))
(do [! try.monad]
[bundle (is (Try (Maybe _.Statement))
(..bundle_module module module_id necessary_dependencies (its archive.#output entry)))]
Expand All @@ -99,8 +100,8 @@
(is _.Statement)
_.code
(by utf8.binary as))]
(in (stack.partial [module_id [(..module_file module_id) entry_content]]
sink))))))
(in (list#composite (list [module_id [(..module_file module_id) entry_content]])
sink))))))

(the .public main_file
"main.rb")
Expand All @@ -114,10 +115,10 @@

(the included_modules
(for_any (_ it)
(-> (Stack [module.ID it])
(-> (List [module.ID it])
(Set module.ID)))
(|>> (stack#each product.left)
(stack#mix set.has (set.empty natural.hash))))
(|>> (list#each product.left)
(set.of_list natural.hash)))

(the .public (package host_dependencies archive program)
Packager
Expand All @@ -126,7 +127,8 @@
order (cache/module.load_order $.key archive)
entries (list.mix' !
(..write_module (module_id_mapping order) necessary_dependencies)
{.#Empty}
(is (List [module.ID [Text Binary]])
(list))
order)
.let [included_modules (..included_modules entries)
imports (|> order
Expand All @@ -144,6 +146,6 @@
_.code
(by utf8.binary as))]]
(in (|> entries
(stack#each product.right)
{.#Top [..main_file imports]}
(list#each product.right)
(list#composite (list [..main_file imports]))
{.#Right}))))
24 changes: 12 additions & 12 deletions stdlib/source/library/lux/control/pattern.lux
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,32 @@

(the .public (complex value)
Complex
(function (_ then else stack)
(then (..consuming value stack))))
(function (_ then else focus)
(then (..consuming value focus))))

(the .public failure
Body
(function (_ then else stack)
(function (_ then else focus)
(else (..empty))))

(the .public (try left right)
(for_any (_ arity_0 arity_1 value)
(type.let [choice (Body arity_1 arity_0 value)]
(-> choice choice
choice)))
(function (_ then else stack)
(function (_ then else focus)
(left then
(function (_ _)
(right then else stack))
stack)))
(right then else focus))
focus)))

(the .public (composite left right)
(for_any (_ arity_0 arity_1 arity_2 value)
(-> (Body arity_1 arity_0 value)
(Body arity_2 arity_1 value)
(Body arity_2 arity_0 value)))
(function (_ then else stack)
(right (left then else) else stack)))
(function (_ then else focus)
(right (left then else) else focus)))

... Pattern
(every .public (Pattern composition input outer inner value)
Expand Down Expand Up @@ -234,8 +234,8 @@
(loop (item [address 0])
(if (natural.< size address)
(..try (match (.list_item# address input))
(function (_ then else stack)
((item (++ address)) then else stack)))
(function (_ then else focus)
((item (++ address)) then else focus)))
..failure))))]))

(every .public (Static it)
Expand All @@ -259,8 +259,8 @@
[..same
(function (_ input)
(if (predicate input)
..success
..failure))])
..success
..failure))])

(the .public (constant = expected)
(for_any (_ it)
Expand Down
148 changes: 85 additions & 63 deletions stdlib/source/library/lux/data/collection/stream.lux
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
[control
["//" continuation (.only Cont)]]
[function
["[0]" predicate]]
["[0]" predicate (.only Predicate)]]
[data
[collection
["[0]" list (.use "[1]#[0]" monad monoid)
["?[1]" \\projection]]
["[0]" stack (.use "[1]#[0]" monad)]]]
["?[1]" \\projection]]]]
[math
[number
["n" natural]]]
Expand All @@ -27,95 +26,118 @@
["[0]" code (.only)
["<[1]>" \\projection]]]]])

(every .public (Stream a)
(Cont [a (Stream a)]))
(every .public (Stream it)
(Cont [it (Stream it)]))

(the .public (iterations step init)
(for_any (_ a b)
(-> (-> a [a b]) a (Stream b)))
(for_any (_ state it)
(-> (-> state [state it])
(-> state (Stream it))))
(let [[next x] (step init)]
(//.pending [x (iterations step next)])))

(the .public (repeated x)
(for_any (_ a)
(-> a (Stream a)))
(//.pending [x (repeated x)]))
(the .public (repeated it)
(for_any (_ it)
(-> it
(Stream it)))
(//.pending [it (repeated it)]))

(the .public (cycle [start next])
(for_any (_ a)
(-> [a (Stack a)] (Stream a)))
(loop (again [head start
tail next])
(//.pending [head (when tail
{.#Empty}
(again start next)

{.#Top head' tail'}
(again head' tail'))])))
(for_any (_ it)
(-> [it (List it)]
(Stream it)))
(let [limit (list.size next)]
(loop (cycle [head start
tail limit])
(//.pending [head (if (n.= limit tail)
(cycle start 0)
(cycle (.list_item# tail next) (++ tail)))]))))

(template.with [<name> <return>]
[(the .public (<name> stream)
(for_any (_ a) (-> (Stream a) <return>))
(for_any (_ it)
(-> (Stream it)
<return>))
(let [[head tail] (//.value stream)]
<name>))]

[head a]
[tail (Stream a)]
[head it]
[tail (Stream it)]
)

(the .public (item idx stream)
(for_any (_ a) (-> Natural (Stream a) a))
(for_any (_ it)
(-> Natural (Stream it)
it))
(let [[head tail] (//.value stream)]
(when idx
0 head
_ (item (-- idx) tail))))

(template.with [<taker> <dropper> <pred_type> <pred_test> <pred_step> <post_test>]
[(the .public (<taker> pred xs)
(for_any (_ a)
(-> <pred_type> (Stream a) (Stack a)))
(let [[x xs'] (//.value xs)]
(if (<post_test> <pred_test>)
(stack.partial x (<taker> <pred_step> xs'))
(stack))))

(the .public (<dropper> pred xs)
(for_any (_ a)
(-> <pred_type> (Stream a) (Stream a)))
(let [[x xs'] (//.value xs)]
(if (<post_test> <pred_test>)
(<dropper> <pred_step> xs')
xs)))]

[while until (-> a Bit) (pred x) pred |>]
[first after Natural (n.= 0 pred) (-- pred) not]
)

(template.with [<splitter> <pred_type> <pred_test> <pred_step>]
[(the .public (<splitter> pred xs)
(for_any (_ a)
(-> <pred_type> (Stream a) [(Stack a) (Stream a)]))
(let [[x xs'] (//.value xs)]
(if <pred_test>
[(stack) xs]
(let [[tail next] (<splitter> <pred_step> xs')]
[{.#Top [x tail]} next]))))]

[split_when (-> a Bit) (pred x) pred]
[split_at Natural (n.= 0 pred) (-- pred)]
)
(the .public (split_when ? it)
(for_any (_ it)
(-> (Predicate it) (Stream it)
[(List it) (Stream it)]))
(let [[stream list] (list.dynamic (function (_ it)
(let [[head tail] (//.value it)]
(if (? head)
{.#None}
{.#Some [tail head]})))
it)]
[list stream]))

(the .public (while ? it)
(for_any (_ it)
(-> (Predicate it) (Stream it)
(List it)))
(let [[list stream] (split_when (predicate.not ?) it)]
list))

(the .public (until ? it)
(for_any (_ it)
(-> (Predicate it)
(Change (Stream it))))
(let [[list stream] (split_when ? it)]
stream))

(the .public (split_at amount it)
(for_any (_ it)
(-> Natural (Stream it)
[(List it) (Stream it)]))
(let [[stream list] (list.static amount
(function (_ it)
(let [[head tail] (//.value it)]
[tail head]))
it)]
[list stream]))

(the .public (first amount it)
(for_any (_ it)
(-> Natural (Stream it)
(List it)))
(let [[list stream] (split_at amount it)]
list))

(the .public (after amount it)
(for_any (_ it)
(-> Natural
(Change (Stream it))))
(let [[list stream] (split_at amount it)]
stream))

(the .public (only predicate stream)
(for_any (_ a) (-> (-> a Bit) (Stream a) (Stream a)))
(for_any (_ it)
(-> (Predicate it)
(Change (Stream it))))
(let [[head tail] (//.value stream)]
(if (predicate head)
(//.pending [head (only predicate tail)])
(only predicate tail))))

(the .public (partition left? xs)
(for_any (_ a)
(-> (-> a Bit) (Stream a)
[(Stream a) (Stream a)]))
(for_any (_ it)
(-> (Predicate it) (Stream it)
[(Stream it) (Stream it)]))
[(..only left? xs)
(..only (predicate.complement left?) xs)])

Expand Down
6 changes: 0 additions & 6 deletions stdlib/source/library/lux/ffi.jvm.lux
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,6 @@
{#Class}
{#Interface}))

(.every StackFrame
(.Nominal "java/lang/StackTraceElement"))

(.every StackTrace
(.Array StackFrame))

(.every Annotation_Parameter
[Text Code])

Expand Down
21 changes: 10 additions & 11 deletions stdlib/source/library/lux/ffi.lux
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
["[0]" text (.only)
["%" \\injection]]
[collection
["[0]" stack]
["[0]" list (.use "[1]#[0]" monoid monad mix)
["[0]" list (.use "[1]#[0]" monoid monad)
["?[1]" \\projection]]]]
["[0]" macro (.only with_names)
["[0]" syntax]
Expand Down Expand Up @@ -761,16 +760,16 @@
(` (<import> (, (code.text (text.replaced .module_delimiter "." class)))))

... else
(when (list.as_stack (text.all_split_by .module_delimiter class))
{.#Top head tail}
(stack.mix (.function (_ sub super)
(` (<get> (, (code.text sub))
(.as (-> Any (..Object .Any))
(, super)))))
(` (<import> (, (code.text head))))
tail)
(when (list.split 1 (text.all_split_by .module_delimiter class))
[(list head) tail]
(list.mix (.function (_ sub super)
(` (<get> (, (code.text sub))
(.as (-> Any (..Object .Any))
(, super)))))
(` (<import> (, (code.text head))))
tail)

{.#Empty}
else
(` (<import> (, (code.text class))))))))

(the (global_definition import! it)
Expand Down
Loading

0 comments on commit cd5a8e1

Please sign in to comment.