Skip to content

Commit

Permalink
Adapting to new List type (part 29).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed May 31, 2024
1 parent 908d6c6 commit 4007d73
Show file tree
Hide file tree
Showing 25 changed files with 233 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,40 +286,41 @@
(_.at (_.its runtime.i64_low_field address)
it))

(the (as_array it)
(Change _.Expression)
(_.do "slice" (.list) it))

(the (list_composite [left right])
(Binary _.Expression)
(let [as_array (is (Change _.Expression)
(for .js
(|>>)

... else
..as_array))]
... (|> (_.array (.list))
... (_.do "concat" (.list (as_array left)
... (as_array right))))
(_.on (.list (_.array (.list)) (as_array left) (as_array right))
(let [it (_.var "it")
left (_.var "left")
right (_.var "right")
item (_.var "item")]
(_.closure (.list it left right)
(all _.then
(_.for item (_.int +0)
(_.< (_.its "length" left)
item)
(_.++ item)
(_.; (_.do "push" (.list (_.at item left)) it)))
(_.for item (_.int +0)
(_.< (_.its "length" right)
item)
(_.++ item)
(_.; (_.do "push" (.list (_.at item right)) it)))
(_.return it)
))))))
(for .js
(|> left
(_.do "concat" (.list right)))

... else
(let [as_array (is (Change _.Expression)
(for .js
(|>>)

... else
..as_array))
as_array (is (Change _.Expression)
(function (as_array it)
(_.do "slice" (.list) it)))]
(_.on (.list (_.array (.list)) (as_array left) (as_array right))
(let [it (_.var "it")
left (_.var "left")
right (_.var "right")
item (_.var "item")]
(_.closure (.list it left right)
(all _.then
(_.for item (_.int +0)
(_.< (_.its "length" left)
item)
(_.++ item)
(_.; (_.do "push" (.list (_.at item left)) it)))
(_.for item (_.int +0)
(_.< (_.its "length" right)
item)
(_.++ item)
(_.; (_.do "push" (.list (_.at item right)) it)))
(_.return it)
)))))))

(the with_list
(Change Bundle)
Expand Down
43 changes: 20 additions & 23 deletions stdlib/source/library/lux/ffi.lux
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
(.function (_ phase archive inputs))
(.function (_ state))
(let [<bindings> [phase archive state]]
(when (?list.value <projection> inputs)
(when (?list.value inputs <projection>)
{try.#Success <inputs>}
<body>

Expand Down Expand Up @@ -236,7 +236,7 @@

(analysis undefined|analysis
[phase archive state]
<code>.end
(<>#in [])
_
{try.#Success [state (extension_analysis (name ..undefined|translation)
(list))]})
Expand Down Expand Up @@ -272,22 +272,18 @@
(Try [state js.Expression]))
(as_expected phase)))]
[state output] (list.mix' !
(sharing [state]
(is state
state)
(is (-> [Synthesis~ Synthesis~] [state (List [Text js.Expression])]
(Try [state (List [Text js.Expression])]))
(.function (_ [key value] [state output])
(when key
(text_synthesis @ key)
(do try.monad
[[state value] (phase archive value state)]
(in [state (list#composite (list [key value])
output)]))

_
(.undefined)))))
[state (list)]
(.function (_ [key value] [state output])
(when key
(text_synthesis @ key)
(do try.monad
[[state value] (phase archive value state)]
(in [state (list#composite (list [key value])
output)]))

_
(.undefined)))
[state (is (List [Text js.Expression])
(list))]
(pairs it))]
(in [state (js.object (list.reversed output))])))

Expand All @@ -307,7 +303,8 @@
[[state value] (phase archive (` (.is .Any (, value))) state)]
(in [state (list#composite (list value (text_analysis key))
output)])))
[state (list)]
[state (is (List Analysis~)
(list))]
it)]
(in [state (extension_analysis (name ..object|translation)
(list.reversed output))])))
Expand Down Expand Up @@ -1034,11 +1031,11 @@

(the .public global
(syntax.macro (_ [type ?list.any
[head tail] (<code>.tuple (<>.and <code>.local (<>.some <code>.local)))])
[head next,tail] (<code>.tuple (<>.and <code>.local (<>.maybe (<>.and <code>.local (<>.some <code>.local)))))])
(with_names ['_]
(let [global (` (.js_constant# (, (code.text head))))]
(when (list.as_stack tail)
{.#Empty}
(when next,tail
{.#None}
(in (list (` (is (.Maybe (, type))
(when (..type_of (, global))
"undefined"
Expand All @@ -1047,7 +1044,7 @@
(, '_)
{.#Some (as (-> Any (, type)) (, global))})))))

{.#Top [next tail]}
{.#Some [next tail]}
(let [delimiter "."]
(in (list (` (is (.Maybe (, type))
(when (..type_of (, global))
Expand Down
3 changes: 2 additions & 1 deletion stdlib/source/library/lux/ffi/node_js.js.lux
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[abstract
[monad (.only do)]]
[control
["[0]" maybe (.use "[1]#[0]" monoid)]
["[0]" maybe (.use "[1]#[0]" monoid)]]
[error
["[0]" try (.only Try)]
["[0]" exception (.only Exception)]]
[macro
Expand Down
4 changes: 2 additions & 2 deletions stdlib/source/library/lux/world/environment.lux
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
(when (ffi.global Object [process env])
{.#Some process/env}
(|> (Object::entries [process/env])
(array.list {.#None})
(list.of_array {.#None})
(list#each (|>> (array.item 0) maybe.trusted)))

{.#None}
Expand Down Expand Up @@ -363,7 +363,7 @@
.js (if ffi.on_node_js?
(|> (node_js.require "os")
maybe.trusted
(as NodeJs_OS)
(as (-> Any NodeJs_OS))
(NodeJs_OS::homedir []))
<default>)
.python (do io.monad
Expand Down
4 changes: 2 additions & 2 deletions stdlib/source/library/lux/world/file.lux
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@
(do maybe.monad
[node_fs (node_js.require "fs")
node_path (node_js.require "path")
.let [node_fs (as ..Fs node_fs)
.let [node_fs (as (-> Any ..Fs) node_fs)
js_delimiter (if ffi.on_node_js?
(JsPath::sep (as ..JsPath node_path))
(JsPath::sep (as (-> Any ..JsPath) node_path))
"/")]]
(in (is (System Future)
(`` (implementation
Expand Down
15 changes: 7 additions & 8 deletions stdlib/source/test/lux/abstract/interval.lux
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
[data
[collection
["[0]" set]
["[0]" list]
["[0]" stack]]]
["[0]" list]]]
[math
["[0]" random (.only Random)]
[number
Expand Down Expand Up @@ -61,8 +60,8 @@
maximum (random.only (|>> (n.= minimum) not)
random.natural)]
(if (<cmp> maximum minimum)
(in (/.between n.enum minimum maximum))
(in (/.between n.enum maximum minimum)))))]
(in (/.between n.enum minimum maximum))
(in (/.between n.enum maximum minimum)))))]

[inner n.<]
[outer n.>]
Expand Down Expand Up @@ -132,8 +131,8 @@
(/.inner? (/.union left_inner right_inner)))
(_.test "The union of 2 outer intervals yields an inner interval when their complements don't overlap, and an outer when they do."
(if (/.overlaps? (/.complement left_outer) (/.complement right_outer))
(/.outer? (/.union left_outer right_outer))
(/.inner? (/.union left_outer right_outer))))
(/.outer? (/.union left_outer right_outer))
(/.inner? (/.union left_outer right_outer))))
)))

(the intersection
Expand All @@ -151,8 +150,8 @@
(/.= some_interval (/.intersection some_interval some_interval)))
(_.test "The intersection of 2 inner intervals yields an inner interval when they overlap, and an outer when they don't."
(if (/.overlaps? left_inner right_inner)
(/.inner? (/.intersection left_inner right_inner))
(/.outer? (/.intersection left_inner right_inner))))
(/.inner? (/.intersection left_inner right_inner))
(/.outer? (/.intersection left_inner right_inner))))
(_.test "The intersection of 2 outer intervals is another outer interval."
(/.outer? (/.intersection left_outer right_outer)))
)))
Expand Down
3 changes: 0 additions & 3 deletions stdlib/source/test/lux/abstract/monad.lux
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
["[0]" pure (.only Pure)]
["[0]" io]]
[data
[collection
["[0]" stack (.use "[1]#[0]" functor mix)]]
["[0]" text (.only)
["%" \\injection]]]
[math
Expand Down Expand Up @@ -68,7 +66,6 @@
Test
(do random.monad
[mono random.natural
poly (random.stack 10 random.natural)
before (random.lower_cased 1)
after (random.upper_cased 1)]
(<| (_.covering /._)
Expand Down
26 changes: 13 additions & 13 deletions stdlib/source/test/lux/abstract/monad/free.lux
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
["[1]T" \\test (.only Injection Comparison)]]]
[data
[collection
["[0]" stack (.use "[1]#[0]" functor)]]]
["[0]" list (.use "[1]#[0]" monad)]]]
[math
["[0]" random]]
[test
Expand All @@ -20,26 +20,26 @@
["[0]" /]])

(the injection
(Injection (/.Free Stack))
(Injection (/.Free List))
(|>> {/.#Pure}))

(the (interpret free)
(for_any (_ it)
(-> (/.Free Stack it)
(Stack it)))
(-> (/.Free List it)
(List it)))
(when free
{/.#Pure value}
(stack value)
(list value)

{/.#Impure effect}
(|> effect
(stack#each interpret)
stack.together)))
(list#each interpret)
list#conjoint)))

(the comparison
(Comparison (/.Free Stack))
(Comparison (/.Free List))
(function (_ = left right)
(by (stack.equivalence =) =
(by (list.equivalence =) =
(..interpret left)
(..interpret right))))

Expand All @@ -53,9 +53,9 @@
/.#Pure /.#Impure])
(all _.and
(_.for [/.functor]
(functorT.spec ..injection ..comparison (is (Functor (/.Free Stack))
(/.functor stack.functor))))
(functorT.spec ..injection ..comparison (is (Functor (/.Free List))
(/.functor list.functor))))
(_.for [/.monad]
(spec ..injection ..comparison (is (Monad (/.Free Stack))
(/.monad stack.functor))))
(spec ..injection ..comparison (is (Monad (/.Free List))
(/.monad list.functor))))
)))
1 change: 0 additions & 1 deletion stdlib/source/test/lux/compiler/language/lux.lux
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
["![1]" \\injection]
["?[1]" \\projection]]
[collection
["[0]" stack]
["[0]" list]]]
[math
["[0]" random (.only Random) (.use "[1]#[0]" monad)]
Expand Down
Loading

0 comments on commit 4007d73

Please sign in to comment.