Skip to content

Commit

Permalink
Added Can abstraction for coupling implementations and values.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Jan 24, 2024
1 parent 4f0d129 commit d0e33fe
Show file tree
Hide file tree
Showing 17 changed files with 719 additions and 599 deletions.
23 changes: 23 additions & 0 deletions stdlib/source/library/lux.lux
Original file line number Diff line number Diff line change
Expand Up @@ -6238,3 +6238,26 @@

{#None}
(failure ..wrong_syntax))))

(every .public (Can ability)
(for_some (_ entity)
[entity
(ability entity)]))

(the .public (able ability entity)
(for_any (_ ability of)
(-> (ability of) of
(Can ability of)))
[entity ability])

(the .public (ability [entity ability])
(for_any (_ ability of)
(-> (Can ability of)
(ability of)))
ability)

(the .public (entity [entity ability])
(for_any (_ ability of)
(-> (Can ability of)
of))
entity)
29 changes: 14 additions & 15 deletions stdlib/source/library/lux/data/bit.lux
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
[equivalence (.only Equivalence)]
[hash (.only Hash)]
[format (.only Format)]]
[meta
["[0]" location]]]])
[control
["[0]" error]
["[0]" try]]]])

(the with_template' (.in_module# .prelude .with_template))

Expand Down Expand Up @@ -58,18 +59,16 @@
[conjunction #1 and]
)

(the .public cannot_decode
Error
(location.with (location.here)
"Cannot decode."))
(the .public not_valid
(error.error "Not valid."))

(the false_injection "#0")
(the true_injection "#1")
(the false_text "#0")
(the true_text "#1")

(the .public (as_text it)
(if it
..true_injection
..false_injection))
..true_text
..false_text))

(the .public format
(Format Text Bit)
Expand All @@ -78,11 +77,11 @@

(the (projection input)
(when input
..false_injection
{.#Right #0}
..false_text
{try.#Success #0}

..true_injection
{.#Right #1}
..true_text
{try.#Success #1}

_
{.#Left ..cannot_decode}))))
{try.#Failure ..not_valid}))))
32 changes: 14 additions & 18 deletions stdlib/source/library/lux/math/random.lux
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,16 @@
["c" complex]
["[0]" i64]]]
[meta
[type
["[0]" object (.only Object
object)]]
[macro
["[0]" template]]]]])

(object.every .public (PRNG [] state)
[#number (object.Method Any [(Object PRNG state) I64])])
(every .public (PRNG state)
(-> state
[(Can PRNG state) I64]))

(every .public (Random of)
(for_any (_ seed)
(State (Object PRNG seed) of)))
(State (Can PRNG seed) of)))

(the Implementation
(template.macro (_ ,interface)
Expand Down Expand Up @@ -90,17 +88,17 @@

(the .public bit
(Random Bit)
(function (_ prng)
(let [[prng output] (object.on ..#number [] prng)]
(function (_ [seed number])
(let [[prng output] (number seed)]
[prng (|> output
(i64.and 1)
(n.= 1))])))

(the .public i64
(Random I64)
(function (_ prng)
(let [[prng left] (object.on ..#number [] prng)
[prng right] (object.on ..#number [] prng)]
(function (_ [seed number])
(let [[[seed number] left] (number seed)
[prng right] (number seed)]
[prng (|> left
(i64.left_shifted 32)
(.i64_+# right))])))
Expand Down Expand Up @@ -311,19 +309,17 @@
(the .public (value prng seed it)
(for_any (_ seed of)
(-> (PRNG seed) seed (Random of seed)
[(Object PRNG seed) of]))
(state.value (object prng seed)
[(Can PRNG seed) of]))
(state.value (able prng seed)
it))

(the .public (prng update return)
(for_any (_ seed)
(-> (-> seed seed) (-> seed I64)
(PRNG seed)))
[#number (object.method
(function (_ next again [this _])
(let [seed (object.state this)]
[(object (prng update return) (update seed))
(return seed)])))])
(function (ability seed)
[(able ability (update seed))
(return seed)]))

(every .public PCG_32
(Record
Expand Down
2 changes: 1 addition & 1 deletion stdlib/source/library/lux/meta/compiler/default/init.lux
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
(the (reader current_module aliases [location offset source_code])
(-> descriptor.Module Aliases Source (///analysis.Operation Reader))
(function (_ state)
{try.#Success [state (///syntax.parse current_module aliases (text.size source_code))]}))
{try.#Success [state (///syntax.parse source_code current_module aliases)]}))

(the (read source reader)
(-> Source Reader (///analysis.Operation [Source Code]))
Expand Down
Loading

0 comments on commit d0e33fe

Please sign in to comment.