Skip to content

Commit

Permalink
Adapting to new List type (part 32).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Jun 5, 2024
1 parent c9edb49 commit 838395f
Show file tree
Hide file tree
Showing 32 changed files with 449 additions and 835 deletions.
212 changes: 111 additions & 101 deletions stdlib/source/library/lux.lux

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions stdlib/source/library/lux/abstract/enum.lux
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@
(the .public (range enum from to)
(for_any (_ it)
(-> (Enum it) it it
(Stack it)))
(List it)))
(let [(open "/#[0]") enum]
(loop (again [end to
output (`` (is (Stack (,, (type_of from)))
{.#Empty}))])
(if (/#< end from)
(again (/#pred end) {.#Top end output})
(if (/#= from to)
(list from)
(loop (again [end to
output (`` (is (List (,, (type_of from)))
(list)))])
(if (/#< end from)
(again (/#pred end) (.list_composite# (list end) output))

(/#< from end)
(again (/#succ end) {.#Top end output})
(/#< from end)
(again (/#succ end) (.list_composite# (list end) output))

... (= end from)
{.#Top end output}))))
... (/#= end from)
(.list_composite# (list end) output))))))
Original file line number Diff line number Diff line change
Expand Up @@ -86,42 +86,7 @@
(Operation Any))
(do phase.monad
[expectedT meta.expected_type]
(..check (check.check expectedT actualT)
... (do [! check.monad]
... [pre check.context
... it (check.check expectedT actualT)
... post check.context
... .let [pre#var_counter (its .#var_counter pre)]]
... (if (n.< (its .#var_counter post)
... pre#var_counter)
... (do !
... [.let [new! (is (-> [Natural (Maybe Type)] (Maybe Natural))
... (function (_ [id _])
... (if (n.< id pre#var_counter)
... {.#Some id}
... {.#None})))
... new_vars (|> post
... (its .#var_bindings)
... (stack.all new!))]
... _ (stack.each' ! (function (_ @new)
... (do !
... [:new: (check.try (check.identity new_vars @new))]
... (when :new:
... {try.#Success :new:}
... (in :new:)

... {try.#Failure error}
... (do !
... [[id _] check.existential
... .let [:new: (..existential' module id)]
... _ (check.bind :new: @new)]
... (in :new:)))))
... new_vars)
... expectedT' (check.clean new_vars expectedT)
... _ (check.with pre)]
... (check.check expectedT' actualT))
... (in it)))
)))
(..check (check.check expectedT actualT))))

(the .public (with_var it)
(for_any (_ it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
[abstract
[monad (.only do)]
["<>" projection]]
[control
["|" pipe]]
[error
["[0]" try]]
[data
["[0]" product]
[collection
["[0]" list (.use "[1]#[0]" functor mix)
["?[1]" \\projection]]
["[0]" stack (.use "[1]#[0]" functor mix)]
["[0]" dictionary]]]
[macro
["[0]" template]]
Expand Down Expand Up @@ -73,21 +70,21 @@
(_.var "String.fromCharCode")))

... [[Text]]
(the text//composite
(the (text//composite it)
(Variadic _.Expression)
(|>> (|.when
(stack)
(_.string "")
(when it
(.list)
(_.string "")

(stack single)
single
(.list single)
single

(stack.partial left rights)
... (|> left (_.do "concat" rights))
(stack#mix (function (_ right left)
(|> left (_.do "concat" (.list right))))
left
rights))))
(.list left right)
(|> left (_.+ right))

rights
(|> (text//composite (.list))
(_.do "concat" rights))))

(the (text//clip [startG endG subjectG])
(Trinary _.Expression)
Expand Down Expand Up @@ -273,8 +270,7 @@

(the list
(Variadic _.Expression)
(|>> list.of_stack
_.array))
_.array)

(the list_size
(Unary _.Expression)
Expand All @@ -294,14 +290,14 @@

... else
(let [as_array (is (Change _.Expression)
(function (as_array it)
(_.do "slice" (.list) it)))
as_array (is (Change _.Expression)
(for .js
(|>>)

... else
..as_array))
as_array (is (Change _.Expression)
(function (as_array it)
(_.do "slice" (.list) it)))]
as_array))]
(_.on (.list (_.array (.list)) (as_array left) (as_array right))
(let [it (_.var "it")
left (_.var "left")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@
_.swap
(_.invokevirtual $StringBuilder "append" (type.method [(list) (list ..$String) $StringBuilder (list)]))
))]
(|>> list.of_stack
(|.when
(|>> (|.when
(list)
(_.string "")

Expand Down Expand Up @@ -463,19 +462,18 @@

(the (lux::list elements)
(Variadic (Bytecode Any))
(let [elements (list.of_stack elements)]
(all _.composite
(_.int (/32.of (.integer (list.size elements))))
(_.anewarray $Object)
(|> elements
list.enumeration
(list#each (function (_ [where what])
(all _.composite
_.dup
(_.int (/32.of (.integer where)))
what
_.aastore)))
(list.complete _.monad)))))
(all _.composite
(_.int (/32.of (.integer (list.size elements))))
(_.anewarray $Object)
(|> elements
list.enumeration
(list#each (function (_ [where what])
(all _.composite
_.dup
(_.int (/32.of (.integer where)))
what
_.aastore)))
(list.complete _.monad))))

(the (lux::list_size it)
(Unary (Bytecode Any))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,17 @@
(the text//composite
(Variadic _.Expression)
(|>> (|.when
(stack)
(.list)
(_.string "")

(stack single)
(.list single)
single

(stack left right)
(.list left right)
(|> left (_.concat right))

parts
(_.apply (.list (_.array (list.of_stack parts)))
(_.apply (.list (_.array parts))
(_.var "table.concat")))))

(the with_text
Expand Down Expand Up @@ -261,8 +261,7 @@

(the list
(Variadic _.Expression)
(|>> list.of_stack
_.array))
_.array)

(the list_size
(Unary _.Expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
[abstract
[monad (.only do)]
["<>" projection]]
[control
["|" pipe]]
[error
["[0]" try]]
["[0]" function]
Expand Down Expand Up @@ -241,21 +239,21 @@
(Trinary _.Expression)
(//runtime.text::index startO partO textO))

(the text::composite
(the (text::composite it)
(Variadic _.Expression)
(|>> list.of_stack
(|.when
(.list)
(_.string "")
(when it
(.list)
(_.string "")

(.list single)
single
(.list single)
single

(.list left right)
(|> left (_.+ right))
(.list left right)
(|> left (_.+ right))

parts
(_.do "join" (.list (_.list parts)) (_.string "")))))
parts
(|> (text::composite (.list))
(_.do "join" (.list (_.list parts))))))

(the with_text
(-> Bundle Bundle)
Expand All @@ -276,8 +274,7 @@

(the list
(Variadic _.Expression)
(|>> list.of_stack
_.list))
_.list)

(the list_size
(Unary _.Expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
[abstract
[monad (.only do)]
["<>" projection]]
[control
["|" pipe]]
[error
["[0]" try]]
["[0]" function]
Expand Down Expand Up @@ -234,21 +232,22 @@
(Trinary _.Expression)
(//runtime.text//index textO partO startO))

(the text//composite
(the (text//composite it)
(Variadic _.Expression)
(|>> list.of_stack
(|.when
(.list)
(_.string "")
(when it
(.list)
(_.string "")

(.list single)
single
(.list single)
single

(.list left right)
(|> left (_.+ right))
(.list left right)
(|> left (_.+ right))

parts
(list#mix _.bit_shl (_.string "") parts))))
parts
(list#mix _.bit_shl
(text//composite (.list))
parts)))

(the with_text
(-> Bundle Bundle)
Expand All @@ -268,11 +267,11 @@

(the io//error!
(Unary _.Expression)
(let [stack_trace (_.do "join" (.list (_.string \n))
{.#None}
_.caller/0)]
(let [trace (_.do "join" (.list (_.string \n))
{.#None}
_.caller/0)]
(|>> (_.+ (_.string (text \n \n)))
(_.+ stack_trace)
(_.+ trace)
_.raise)))

(the with_io
Expand All @@ -283,8 +282,7 @@

(the list
(Variadic _.Expression)
(|>> list.of_stack
_.array))
_.array)

(the list_size
(Unary _.Expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
)

(every .public (Variadic it)
(-> (Stack it)
(-> (List it)
it))

(the .public (variadic extension)
Expand All @@ -87,4 +87,4 @@
(let [! phase.monad]
(|> inputsS
(list.each' ! (phase archive))
(by ! each (|>> list.as_stack extension))))))
(by ! each extension)))))
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
[collection
["[0]" list (.use "[1]#[0]" monad)
["?[1]" \\projection]]
["[0]" stack (.use "[1]#[0]" functor)]
["[0]" sequence]]]
[math
[number (.only hex)
Expand Down
Loading

0 comments on commit 838395f

Please sign in to comment.