Skip to content

Commit

Permalink
Parsing machinery for objects.
Browse files Browse the repository at this point in the history
Also, an experimental extensible pattern-matching implementation.
  • Loading branch information
eduardoejp committed Aug 9, 2023
1 parent 8fe3432 commit 51116cd
Show file tree
Hide file tree
Showing 30 changed files with 710 additions and 68 deletions.
1 change: 1 addition & 0 deletions documentation/bookmark/business/decision_making.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Reference

0. [On the importance of non-goals](https://www.dsebastien.net/on-the-importance-of-non-goals/)
0. [Analytic hierarchy process](https://en.wikipedia.org/wiki/Analytic_hierarchy_process)
0. [Causal Explanations Considered Harmful: On the logical fallacy of causal projection](https://superbowl.substack.com/p/causal-explanations-considered-harmful)
0. [Why Developing Negative Capability is Critical in Leadership](https://www.leadingsapiens.com/developing-negative-capability-leadership/)
Expand Down
1 change: 1 addition & 0 deletions documentation/bookmark/compilation/target/c++.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

# Reference

0. [Writing custom C++20 coroutine systems](https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/coroutines-c++20/)
0. [STX](https://lamarrr.github.io/STX/)
0. [The joys and perils of C and C++ aliasing, Part 1](https://developers.redhat.com/blog/2020/06/02/the-joys-and-perils-of-c-and-c-aliasing-part-1#)
0. [The joys and perils of aliasing in C and C++, Part 2](https://developers.redhat.com/blog/2020/06/03/the-joys-and-perils-of-aliasing-in-c-and-c-part-2)
Expand Down
1 change: 1 addition & 0 deletions documentation/bookmark/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@

## General

0. [Readings in Database Systems, 5th Edition](http://www.redbook.io/)
0. [How FoundationDB works and why it works](https://blog.the-pans.com/notes-on-the-foundationdb-paper/)
0. [FeatureBase: The First OLAP Database Built Entirely on Bitmaps](https://www.featurebase.com/)
0. [FeatureBase](https://github.com/FeatureBaseDB/featurebase)
Expand Down
1 change: 1 addition & 0 deletions documentation/bookmark/health.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Reference

0. [From Worst-Case CANCER to Best-Case Scenario (NO CANCER)](https://www.youtube.com/watch?v=6JD_JzprK5U)
0. [How To Naturally Reverse Premature Graying of Hair](https://www.youtube.com/watch?v=LMLdClbwqhE)
0. [Contraceptive Properties of Stevia rebaudiana](https://www.science.org/doi/10.1126/science.162.3857.1007.a)
0. [The #1 Nontoxic Vegetable Wash](https://www.youtube.com/watch?v=GKLZpquBc_4)
Expand Down
2 changes: 1 addition & 1 deletion documentation/bookmark/play/game/engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## General

0. []()
0. [Books I had to read to develop a game engine](https://www.haroldserrano.com/blog/books-i-used-to-develop-a-game-engine)
0. [MonoGame: One framework for creating powerful cross-platform games](https://www.monogame.net/)
0. [Heaps.io](https://heaps.io/index.html)
0. [The Machinery](https://ourmachinery.com/)
Expand Down
4 changes: 4 additions & 0 deletions documentation/bookmark/tool/text_editor/code_folding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Reference

0. [ts-fold: Code-folding using tree-sitter](https://github.com/emacs-tree-sitter/ts-fold)

2 changes: 2 additions & 0 deletions documentation/bookmark/type_theory/unit.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Reference

0. [uom: Units of measurement -- type-safe zero-cost dimensional analysis](https://github.com/iliekturtles/uom)
0. [Dimensional analysis](https://en.wikipedia.org/wiki/Dimensional_analysis)
0. [mp-units - A Units Library for C++](https://github.com/mpusz/units)
0. https://en.wikipedia.org/wiki/Metric_prefix#Metric_units
0. [unittyped: An extendable library for type-safe computations including units.](https://hackage.haskell.org/package/unittyped)
Expand Down
3 changes: 2 additions & 1 deletion stdlib/source/library/lux/control/function/predicate.lux
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
(All (_ of)
(-> (Predicate of)
(Predicate of)))
(|>> predicate .not))
(|>> predicate
.not))

(alias [not]
..complement)
Expand Down
20 changes: 11 additions & 9 deletions stdlib/source/library/lux/control/logic.lux
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
[monad (.only Monad
do)]]
[control
["[0]" try (.only Try) (.use "[1]#[0]" monad)]
["[0]" object (.only Object)]]
["[0]" try (.only Try) (.use "[1]#[0]" monad)]]
[data
["[0]" product]
["[0]" text]
Expand All @@ -27,7 +26,8 @@
["[0]" frac]]]
[meta
[type
["[0]" nominal]]
["[0]" nominal]
["[0]" object (.only Object object)]]
[macro
["^" pattern]]]]])

Expand Down Expand Up @@ -158,8 +158,9 @@
#unified (object.method
(function (_ next again [this [reference]])
(when (object.as (object.class this) reference)
{.#Some [reference#= reference_value]}
(let [[this#= this_value] (object.state this)]
{.#Some reference}
(let [[reference#= reference_value] (object.state reference)
[this#= this_value] (object.state this)]
(if (this#= reference_value this_value)
..success
..failure))
Expand All @@ -171,7 +172,7 @@
(All (_ of)
(-> (Equivalence of) of
(Term of)))
(object.new ..constant_class [equivalence it]))
(object ..constant_class [equivalence it]))

(nominal.every (Variable of)
ID
Expand Down Expand Up @@ -300,8 +301,9 @@
#unified (object.method
(function (_ next again [this [reference]])
(when (object.as (object.class this) reference)
{.#Some reference_id}
(unified_variables reference_id this)
{.#Some reference}
(let [reference_id (object.state reference)]
(unified_variables reference_id this))

{.#None}
(do ..monad
Expand Down Expand Up @@ -331,5 +333,5 @@
(function (_ context)
(let [id (dictionary.size context)]
(list [(dictionary.has id [equivalence {.#Left id}] context)
(object.new ..variable_class (nominal.abstraction id))]))))
(object ..variable_class (nominal.abstraction id))]))))
)
43 changes: 43 additions & 0 deletions stdlib/source/library/lux/control/pattern.lux
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

... ["Type-safe pattern combinators" by Morten Rhiger](https://core.ac.uk/works/9613163)
(.require
[library
[lux (.except Pattern
when)
[control
[pure (.only Pure)]
[function
[predicate (.only Predicate)]]]
[meta
["[0]" type]]]]
[/
["[0]" input]
["[0]" match]
["[0]" pattern]
["[0]" clause (.only Clause Pattern)]])

(the .public (when input clause)
(All (_ input value)
(-> input (Clause input value)
value))
(clause input
(function (_ _)
(undefined))))

(the .public (match? pattern input)
(All (_ of)
(-> (Pattern of Bit Bit)
(Predicate of)))
(<| (..when input)
(all clause.or
(clause.clause pattern true)
(clause.clause pattern.any false))))

(the .public (abstraction pattern body)
(All (_ term input value)
(-> (Pattern input term value) term
(-> input value)))
(function (_ input)
(..when input (clause.clause pattern body))))
68 changes: 68 additions & 0 deletions stdlib/source/library/lux/control/pattern/body.lux
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
[library
[lux (.except or and)
[meta
["[0]" type]]]]
[//
["[0]" input]
["[0]" output]])

(every .public (Then arity value)
(-> arity
value))

(every .public Constant
(Then input.Zero))

(every .public Else
Constant)

(every .public (Body outer inner value)
(-> (Then inner value) (Else value)
(Then outer value)))

(every .public Zero
(All (_ arity value)
(Body arity arity value)))

(the .public success
Zero
(function (_ next exit)
next))

(every .public (Succ of)
(All (_ arity value)
(|> (Body arity (input.Succ of arity) value)
(output.Succ of))))

(the .public (succ value)
Succ
(function (_ next exit stack)
(next (input.succ value stack))))

(the .public failure
Body
(function (_ next exit stack)
(exit (input.zero))))

(the .public (or left right)
(All (_ arity_0 arity_1 value)
(type.let [choice (Body arity_0 arity_1 value)]
(-> choice choice
choice)))
(function (_ next exit stack)
(left next
(function (_ _)
(right next exit stack))
stack)))

(the .public (and left right)
(All (_ 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 (_ input exit stack)
(right (left input exit) exit stack)))
40 changes: 40 additions & 0 deletions stdlib/source/library/lux/control/pattern/clause.lux
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
[library
[lux (.except Pattern
or)
[meta
["[0]" type]]]]
[//
["[0]" input]
["[0]" match]
["[0]" body (.only Body)]])

(every .public (Pattern input negative value)
(Ex (_ arity)
(type.let [positive (body.Then arity value)]
[(-> match.Constant (-> negative positive))
(-> input (Body input.Zero arity value))])))

(every .public (Clause input value)
(-> input (body.Else value)
value))

(the .public (clause pattern body)
(All (_ input term value)
(-> (Pattern input term value) term
(Clause input value)))
(function (_ input exit)
(let [[number match] pattern]
((match input) (number match.constant body) exit []))))

(the .public (or left right)
(All (_ input value)
(-> (Clause input value) (Clause input value)
(Clause input value)))
(function (_ input exit)
(left input
(function (_ _)
(right input exit)))))
23 changes: 23 additions & 0 deletions stdlib/source/library/lux/control/pattern/input.lux
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
[library
[lux (.except)]])

(every .public Zero
[])

(the .public zero
(template (_)
[[]]))

(every .public (One of)
of)

(every .public (Succ of pred)
(And of pred))

(the .public succ
(template (_ of pred)
[[of pred]]))
45 changes: 45 additions & 0 deletions stdlib/source/library/lux/control/pattern/match.lux
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
[library
[lux (.except)]]
[//
["[0]" input]
["[0]" output]])

(every .public (Match negative positive value)
(-> negative positive
value))

(every .public Constant
(All (_ value)
(Match (output.One value) input.Zero
value)))

(the .public constant
Constant
(function (_ one (input.zero))
one))

(every .public (Natural negative_change positive_change)
(All (_ value negative positive)
(-> (Match negative positive
value)
(Match (negative_change negative) (positive_change positive)
value))))

(every .public Zero
(Natural output.One input.One))

(the .public zero
Zero
(|>>))

(every .public (Succ of)
(Natural (output.Succ of) (input.Succ of)))

(the .public (succ pred)
Succ
(function (_ negative (input.succ ++ --))
(pred (negative ++) --)))
14 changes: 14 additions & 0 deletions stdlib/source/library/lux/control/pattern/output.lux
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
[library
[lux (.except)]])

(every .public One
(All (_ of)
of))

(every .public (Succ of pred)
(-> of
pred))
Loading

0 comments on commit 51116cd

Please sign in to comment.