Skip to content

Commit

Permalink
Adapting to new List type (part 25).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed May 23, 2024
1 parent 094320b commit 4ff0313
Show file tree
Hide file tree
Showing 15 changed files with 243 additions and 310 deletions.
4 changes: 0 additions & 4 deletions stdlib/source/library/lux.lux
Original file line number Diff line number Diff line change
Expand Up @@ -3877,10 +3877,6 @@
else
(failure ..wrong_syntax))))

(the' .public bindings_must_be_pairs
Error
"Bindings must be pairs (i.e. they must be an even number).")

(the' .public let
Macro
(macro (_ tokens)
Expand Down
103 changes: 51 additions & 52 deletions stdlib/source/library/lux/abstract/comonad.lux
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
["[0]" try]]
[data
[collection
["[0]" stack (.use "[1]#[0]" mix)]
["[0]" list (.use "[1]#[0]" mix)]]]
["[0]" list]]]
[math
[number
["n" natural]]]
Expand Down Expand Up @@ -38,60 +37,60 @@
(the meta#monad (.in_module# .prelude .meta#monad))
(the failure (.in_module# .prelude .failure))

(the ?#value (.in_module# .prelude .?#value))
(the ?#each (.in_module# .prelude .?#each))
(the ?#in (.in_module# .prelude .?#in))
(the ?#any (.in_module# .prelude .?#any))
(the ?#local (.in_module# .prelude .?#local))
(the ?#tuple (.in_module# .prelude .?#tuple))
(the ?#either (.in_module# .prelude .?#either))
(the ?#and (.in_module# .prelude .?#and))
(the ?#some (.in_module# .prelude .?#some))
(the ?#rest (.in_module# .prelude .?#rest))

(the .public be
(macro (_ tokens)
(when (is (Maybe [(Maybe Text) Code (List Code) Code])
(when tokens
(list {.#Tuple _ (list {.#Name _ ["" name]} comonad)}
{.#Tuple _ bindings}
body)
{.#Some [{.#Some name} comonad bindings body]}

(list comonad
{.#Tuple _ bindings}
body)
{.#Some [{.#None} comonad bindings body]}

_
{.#None}))
{.#Some [?name comonad bindings body]}
(when (stack.pairs (list.as_stack bindings))
{try.#Success bindings}
(do meta#monad
['_ (generated_name "_")
'each (generated_name "each")
'disjoint (generated_name "disjoint")]
(let [body' (stack#mix (is (-> [Code Code] Code Code)
(function (_ binding body')
(expansion.let [<default> (` (|> (, value) (, 'disjoint) ((, 'each) (function ((, '_) (, var)) (, body')))))]
(let [[var value] binding]
(when var
{.#Name _ ["" _]}
<default>
(when (|> (all ?#and
(?#either (?#tuple (?#and (?#each (|>> {.#Some}) ?#local) ?#any))
(?#and (?#in {.#None}) ?#any))
(?#tuple (?#some (?#and ?#any ?#any)))
?#any)
(?#value tokens))
{.#Some [[?name comonad] bindings body]}
(do meta#monad
['_ (generated_name "_")
'each (generated_name "each")
'disjoint (generated_name "disjoint")]
(let [body' (list.mix (is (-> [Code Code] Code Code)
(function (_ binding body')
(expansion.let [<default> (` (|> (, value)
(, 'disjoint)
((, 'each) (function ((, '_) (, var)) (, body')))))]
(let [[var value] binding]
(when var
{.#Name _ ["" _]}
<default>

{.#Name _ _}
(` ((, var) (, value) (, body')))
{.#Name _ _}
(` ((, var) (, value) (, body')))

_
<default>)))))
body
(stack.reversed bindings))]
(in (list (when ?name
{.#Some name}
(let [name {.#Name provenance.dummy ["" name]}]
(` (.when (, comonad)
(, name)
(.when (, name)
[(, 'each) (,' out) (, 'disjoint)]
(, body')))))

{.#None}
_
<default>)))))
body
(list.reversed bindings))]
(in (list (when ?name
{.#Some name}
(let [name {.#Name provenance.dummy ["" name]}]
(` (.when (, comonad)
[(, 'each) (,' out) (, 'disjoint)]
(, body'))))))))

{try.#Failure _}
(..failure .bindings_must_be_pairs))
(, name)
(.when (, name)
[(, 'each) (,' out) (, 'disjoint)]
(, body')))))

{.#None}
(` (.when (, comonad)
[(, 'each) (,' out) (, 'disjoint)]
(, body'))))))))

{.#None}
else
(..failure .wrong_syntax))))
10 changes: 5 additions & 5 deletions stdlib/source/library/lux/abstract/enum.lux
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
output (`` (is (Stack (,, (type_of from)))
{.#Empty}))])
(if (/#< end from)
(again (/#pred end) {.#Top end output})
(again (/#pred end) {.#Top end output})

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

... (= end from)
{.#Top end output}))))
... (= end from)
{.#Top end output}))))
150 changes: 61 additions & 89 deletions stdlib/source/library/lux/abstract/monad.lux
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,12 @@

(.using
[library
[lux (.except all only)
[lux (.except)
[meta
["[0]" provenance]]]]
[//
[functor (.only Functor)]])

(the (stack#mix f init xs)
(for_any (_ part whole)
(-> (-> part whole whole) whole (Stack part)
whole))
(when xs
{.#Empty}
init

{.#Top x xs'}
(stack#mix f (f x init) xs')))

(the (reversed xs)
(for_any (_ it)
(-> (Stack it)
(Stack it)))
(stack#mix (function (_ head tail) {.#Top head tail})
{.#Empty}
xs))

(the (pairs xs)
(for_any (_ it)
(-> (Stack it)
(Stack [it it])))
(when xs
{.#Top x1 {.#Top x2 xs'}}
{.#Top [x1 x2] (pairs xs')}

_
{.#Empty}))

(every .public (Monad !)
(Interface
(is (Functor !)
Expand All @@ -57,68 +27,70 @@
(the _meta#monad (.in_module# .prelude .meta#monad))
(the _failure (.in_module# .prelude .failure))
(the _expansion#let (.in_module# .prelude .expansion#let))
(the list#as_stack (.in_module# .prelude .list#as_stack))
(the list#reversed (.in_module# .prelude .list#reversed))
(the list#mix (.in_module# .prelude .list#mix))

(the ?#value (.in_module# .prelude .?#value))
(the ?#each (.in_module# .prelude .?#each))
(the ?#in (.in_module# .prelude .?#in))
(the ?#any (.in_module# .prelude .?#any))
(the ?#local (.in_module# .prelude .?#local))
(the ?#tuple (.in_module# .prelude .?#tuple))
(the ?#either (.in_module# .prelude .?#either))
(the ?#and (.in_module# .prelude .?#and))
(the ?#some (.in_module# .prelude .?#some))
(the ?#rest (.in_module# .prelude .?#rest))

(the .public do
(macro (_ tokens)
(when (is (Maybe [(Maybe Text) Code (List Code) Code])
(when tokens
(list {.#Tuple _ (list {.#Name _ ["" name]} monad)}
{.#Tuple _ bindings}
body)
{.#Some [{.#Some name} monad bindings body]}

(list monad
{.#Tuple _ bindings}
body)
{.#Some [{.#None} monad bindings body]}

_
{.#None}))
{.#Some [?name monad bindings body]}
(if (|> bindings .list_size# .integer (.int_%# +2) (.i64_=# +0))
(_do _meta#monad
['_ (_generated_name "'_")
'each (_generated_name "'each")
'conjoint (_generated_name "'conjoint")]
(let [[module proper] (name ..do)
name (is (-> Text Code)
(|>> (.text_composite# module " " proper " ")
[""]
[provenance.dummy]
{.#Name}))
body' (stack#mix (is (-> [Code Code] Code Code)
(function (_ binding body')
(<| (_expansion#let [<default> (` (|> (, value)
((, 'each) (function ((, '_) (, var))
(, body')))
(, 'conjoint)))])
(let [[var value] binding]
(when var
{.#Name _ ["" _]}
<default>

{.#Name _ _}
(` ((, var) (, value) (, body')))

_
<default>)))))
body
(reversed (pairs (list#as_stack bindings))))]
(in (list (when ?name
{.#Some name}
(let [name {.#Name provenance.dummy ["" name]}]
(` (.when (, monad)
(, name)
(.when (, name)
[(, 'each) (,' in) (, 'conjoint)]
(, body')))))

{.#None}
(` (.when (, monad)
(when (|> (all ?#and
(?#either (?#tuple (?#and (?#each (|>> {.#Some}) ?#local) ?#any))
(?#and (?#in {.#None}) ?#any))
(?#tuple (?#some (?#and ?#any ?#any)))
?#any)
(?#value tokens))
{.#Some [[?name monad] bindings body]}
(_do _meta#monad
['_ (_generated_name "'_")
'each (_generated_name "'each")
'conjoint (_generated_name "'conjoint")]
(let [[module proper] (name ..do)
name (is (-> Text Code)
(|>> (.text_composite# module " " proper " ")
[""]
[provenance.dummy]
{.#Name}))
body' (list#mix (is (-> [Code Code] Code Code)
(function (_ binding body')
(<| (_expansion#let [<default> (` (|> (, value)
((, 'each) (function ((, '_) (, var))
(, body')))
(, 'conjoint)))])
(let [[var value] binding]
(when var
{.#Name _ ["" _]}
<default>

{.#Name _ _}
(` ((, var) (, value) (, body')))

_
<default>)))))
body
(list#reversed bindings))]
(in (list (when ?name
{.#Some name}
(let [name {.#Name provenance.dummy ["" name]}]
(` (.when (, monad)
(, name)
(.when (, name)
[(, 'each) (,' in) (, 'conjoint)]
(, body'))))))))
(_failure .bindings_must_be_pairs))
(, body')))))

{.#None}
(` (.when (, monad)
[(, 'each) (,' in) (, 'conjoint)]
(, body'))))))))

{.#None}
(_failure .wrong_syntax))))
Expand Down
9 changes: 1 addition & 8 deletions stdlib/source/library/lux/abstract/monad/indexed.lux
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
[data
[collection
["[0]" list (.use "[1]#[0]" functor mix)
["?[1]" \\projection]]
["[0]" stack (.use "[1]#[0]" functor mix)]]]
["?[1]" \\projection]]]]
["[0]" macro (.only)
["[0]" syntax]]
[meta
Expand Down Expand Up @@ -58,12 +57,6 @@
?list.any)
binding))

(the (pair_stack [binding value])
(for_any (_ it)
(-> [it it]
(Stack it)))
(stack binding value))

(the named_monad
(Projection [(Maybe Text) Code])
(?.either (?code.tuple (?.and (by ?.monad each (|>> {.#Some})
Expand Down
Loading

0 comments on commit 4ff0313

Please sign in to comment.