Skip to content

Commit

Permalink
Added support for literal syntax for Fraction and Rational numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Jan 22, 2024
1 parent 8fc06c4 commit cc09e2f
Show file tree
Hide file tree
Showing 38 changed files with 459 additions and 211 deletions.
1 change: 1 addition & 0 deletions documentation/bookmark/business/hiring.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Reference

0. [Those jobs you’re applying to? They might not be real](https://www.marketplace.org/2024/01/03/those-jobs-youre-applying-to-they-might-not-be-real/)
0. [Draft: Matching ideas & upcoming talents](https://www.draftcommunity.xyz/)
0. [Spotting Talent: A new book offers surprising insights into the traits of outstanding people.](https://www.city-journal.org/spotting-talent)
0. [Talent: How to Identify Energizers, Creatives, and Winners Around the World](https://www.amazon.com/Talent-Identify-Energizers-Creatives-Winners/dp/1250275814/)
Expand Down
4 changes: 4 additions & 0 deletions documentation/bookmark/business/metric.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Reference

0. [16 Startup Metrics](https://a16z.com/16-startup-metrics/)

1 change: 1 addition & 0 deletions documentation/bookmark/css.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# Reference

0. [Flexbugs: A community-curated list of flexbox issues and cross-browser workarounds for them](https://github.com/philipwalton/flexbugs)
0. [StyleX](https://stylexjs.com/)
0. [Introducing StyleX](https://stylexjs.com/blog/introducing-stylex/)
0. [CSS Hooks: Inline styles doing what we thought they couldn't](https://css-hooks.com/)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Reference

0. []()
0. [Fitts's law](https://en.wikipedia.org/wiki/Fitts%27s_law)
0. [Smarter Defaults by Paying Attention](https://textslashplain.com/2022/02/15/smarter-defaults-by-paying-attention/)
0. [Formality Considered Harmful: Experiences, Emerging Themes, and Directions on the Use of Formal Representations in Interactive Systems](https://andymatuschak.org/files/papers/Shipman%20and%20Marshall%20-%201999%20-%20Formality%20Considered%20Harmful%20Experiences,%20Emergin.pdf)

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

0. [Coastal Risk Screening Tool](https://coastal.climatecentral.org/)
0. [Open Sustainable Technology](https://opensustain.tech/)
0. [POLLUTANT ABSORPTION SYSTEM](https://www.pollutantabsorptionsystem.com/)
0. [Fungi may offer ‘jaw-dropping’ solution to climate change](https://thehill.com/policy/equilibrium-sustainability/4034986-fungi-may-offer-jaw-dropping-solution-to-climate-change/)
0. [Towards sustainable desalination](https://www.unep.org/news-and-stories/story/towards-sustainable-desalination)
Expand Down
4 changes: 4 additions & 0 deletions documentation/bookmark/economics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Reference

0. [Economic surveillance of EU economies](https://economy-finance.ec.europa.eu/economic-surveillance-eu-economies_en)

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

0. [Global Outbreaks](https://preventepidemics.org/map/?=undefined)
0. [Search for a rare disease]https://www.orpha.net/consor/cgi-bin/Disease.php?lng=EN()

39 changes: 39 additions & 0 deletions documentation/bookmark/math/statistics/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Reference

0. [International Database: World Population Estimates and Projections](https://www.census.gov/programs-surveys/international-programs/about/idb.html)
0. [Purchasing Managers' Index](https://www.pmi.spglobal.com/)
0. [STATE RESILIENCE INDEX: Measuring Capacities and Capabilities In 154 Countries](https://www.fundforpeace.org/SRI/about.html)
0. [](https://www.dashboard-deutschland.de/)
0. [Human Development Index](https://hdr.undp.org/data-center/human-development-index#/indicies/HDI)
0. [InfraTracker](https://infratracker.gihub.org/)
0. [Inflation rate, average consumer prices](https://www.imf.org/external/datamapper/PCPIPCH@WEO/OEMDC)
0. [Trading Economics](https://tradingeconomics.com/indicators)
0. [](https://tradingeconomics.com/matrix)
0. [](https://tradingeconomics.com/united-states/calendar)
0. [Global Slavery Index](https://www.walkfree.org/global-slavery-index/map/)
0. [OFR Financial Stress Index](https://www.financialresearch.gov/financial-stress-index/)
0. [Fragile States Index](https://fragilestatesindex.org/)
0. [Global Conflict Tracker](https://www.cfr.org/global-conflict-tracker)
0. [Conflict Forecast](https://conflictforecast.org/)
0. [Corruption Perceptions Index](https://www.transparency.org/en/cpi/2022)
0. [Tax Justice Network](https://taxjustice.net/country-profiles/)
0. [Uppsala Conflict Data Program](https://ucdp.uu.se/encyclopedia)
0. [Water Risk Atlas](https://www.wri.org/applications/aqueduct/water-risk-atlas/#/?advanced=false&basemap=hydro&indicator=w_awr_def_tot_cat&lat=52.802761415419674&lng=-32.43164062500001&mapMode=view&month=1&opacity=0.5&ponderation=DEF&predefined=false&projection=absolute&scenario=optimistic&scope=baseline&threshold&timeScale=annual&year=baseline&zoom=5)
0. [Geopolitical risk dashboard](https://www.blackrock.com/corporate/insights/blackrock-investment-institute/interactive-charts/geopolitical-risk-dashboard)
0. [Armed Conflict Location & Event Data Project (ACLED)](https://acleddata.com/dashboard/#/dashboard)
0. [Global Maritime Traffic](https://globalmaritimetraffic.org/gmtds.html?$root.map.zoom=3&$root.map.center={%22lat%22:-0.08789059053082422,%22lng%22:0}&$root.projectionSelect=%22EPSG:3857%22)
0. [Global Energy Monitor](https://globalenergymonitor.org/)
0. [Population Density Explorer](https://populationexplorer.org/)
0. [Energy Statistics Data Browser](https://www.iea.org/data-and-statistics/data-tools/energy-statistics-data-browser?country=WORLD&fuel=Energy%20supply&indicator=TESbySource)
0. [ND-GAIN Country Index](https://gain.nd.edu/our-work/country-index/rankings/)
0. [Productive Capacities Index](https://unctadstat.unctad.org/EN/Pci.html)
0. [water, peace and Security](https://waterpeacesecurity.org/map)
0. [Global Organized Crime Index](https://ocindex.net/)
0. [Global Terrorism Index](https://www.visionofhumanity.org/maps/global-terrorism-index/#/)
0. [Global Peace Index](https://www.visionofhumanity.org/maps/#/)
0. [Ecological Threat Report](https://www.visionofhumanity.org/maps/ecological-threat-report/#/)
0. [Mexico Peace Index](https://www.visionofhumanity.org/maps/mexico-peace-index/#/)
0. [Positive Peace Index](https://www.visionofhumanity.org/maps/positive-peace-index/#/)
0. [US Peace Index](https://www.visionofhumanity.org/maps/us-peace-index/#/)
0. [UK Peace Index](https://www.visionofhumanity.org/maps/uk-peace-index/#/)

4 changes: 4 additions & 0 deletions documentation/bookmark/media/podcast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Reference

0. [Erik Torenberg on the Evolution of Media](https://www.youtube.com/watch?v=beR7vqtW_X4)

1 change: 1 addition & 0 deletions documentation/bookmark/music.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# Reference

0. [What's the difference between 3/4 and 6/8 time?](https://www.youtube.com/watch?v=N4q2kBe82-o)
0. [F2P, a new business model for music.](https://danfowler.substack.com/p/f2p-a-new-business-model-for-music)
0. [](https://oscilloscopemusic.com/)
0. [Introduction to Music (Theory)](https://soundcloud.com/languagetransfer/sets/introduction-to-music-theory)
Expand Down
5 changes: 5 additions & 0 deletions documentation/bookmark/news.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Reference

0. [EMM News Explorer: News analysis, across languages and over time](http://emm.newsexplorer.eu/)
0. [GDELT Project](https://www.gdeltproject.org/)

1 change: 1 addition & 0 deletions documentation/bookmark/science.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Reference

0. [Invisible College](https://invisible.college/)
0. [Beware the Man of Many Studies: Low-quality literatures mean meta-analyses are frequently worse than single studies](https://cremieux.substack.com/p/beware-the-man-of-many-studies)

1 change: 1 addition & 0 deletions documentation/bookmark/security/privacy.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Reference

0. [NO2DIGITALID](https://bigbrotherwatch.org.uk/campaigns/no2digitalid/)
0. [Choose your browser carefully](https://www.unixsheikh.com/articles/choose-your-browser-carefully.html)
0. ["Demystifying Privacy Preserving Computing" by Tejas Chopra (Strange Loop 2022)](https://www.youtube.com/watch?v=10Qj0eYqbuo)
0. [Mullvad Browser](https://mullvad.net/en/browser)
Expand Down
1 change: 1 addition & 0 deletions documentation/bookmark/tool/text_editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@

## General

0. [Byte Positions Are Better Than Line Numbers](https://www.computerenhance.com/p/byte-positions-are-better-than-line)
0. [Lesser Known Terminal Editors](https://codeberg.org/CoopCoding/Lesser-Known-Terminal-Editors)
0. [Gamut: The Idea Editor](https://gamut.ink/)
0. [How to Build a Text Editor With Java](https://www.youtube.com/playlist?list=PLIRBoI92yManB1eHCupZ6iG61qMTA9hWe)
Expand Down
4 changes: 4 additions & 0 deletions documentation/bookmark/transparency.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Reference

0. [Supreme Connections](https://projects.propublica.org/supreme-connections/)

26 changes: 18 additions & 8 deletions lux-mode/lux-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,25 @@ Called by `imenu--generic-function'."
(defconst lux-font-lock-keywords
(eval-when-compile
(let* ((natural "[0-9][0-9,]*")

(sign (altRE "-" "\\+"))
(integer (concat sign natural))

(decimal_separator "\\.")
(revolution (concat decimal_separator natural))
(decimal (concat integer revolution "\\(\\(e\\|E\\)" integer "\\)?"))

(fraction_separator "/")
(fraction (concat natural fraction_separator natural))
(rational (concat integer fraction_separator natural))

(identifier_h|label "#")
(identifier_h|type "[:upper:]")
;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Regexp-Special.html
(identifier_t "][)(}{.\"[:space:]")
(identifier_h (concat identifier_t "0-9"))
(sign (altRE "-" "\\+"))
(identifier (concat (-class identifier_h) (-class identifier_t) "*"))
(integer (concat sign natural))
(bitRE (literal (altRE "#0" "#1")))
(natRE (literal natural))
(int&decRE (literal (concat integer "\\(\\." natural "\\(\\(e\\|E\\)" integer "\\)?\\)?")))
(revRE (literal (concat "\\." natural)))
(specialRE (let (;; Control
(control//flow (altRE "when" "exec" "let" "loop" "do" "be"
"if" "unless"))
Expand Down Expand Up @@ -455,9 +462,12 @@ Called by `imenu--generic-function'."
(typeRE (concat global_prefix (+class identifier_h|type) (-class identifier_t) "*"))
(labelRE (concat global_prefix (+class identifier_h|label) (-class identifier_t) "+"))
(literalRE (altRE bitRE ;; Bit literals
natRE ;; Nat literals
int&decRE ;; Int literals && Dec literals
revRE ;; Rev literals
(literal natural)
(literal integer)
(literal revolution)
(literal decimal)
(literal fraction)
(literal rational)
)))
`(;; Special forms
(,specialRE 1 font-lock-builtin-face)
Expand Down
10 changes: 7 additions & 3 deletions stdlib/source/library/lux/math/number/fraction.lux
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
(the .public fraction
(syntax.macro (_ [numerator <code>.any
?denominator (<>.maybe <code>.any)])
(in (list (` (normal [..#numerator (, numerator)
..#denominator (, (maybe.else (' 1) ?denominator))]))))))
(in (list (` (..normal [..#numerator (, numerator)
..#denominator (, (maybe.else (' 1) ?denominator))]))))))

(the .public (= parameter subject)
(-> It It
Expand Down Expand Up @@ -171,7 +171,8 @@
[..#numerator /#denominator
..#denominator /#numerator])

(the separator "/")
(the .public separator
"/")

(the .public (as_text (open "/[0]"))
(text.Injection It)
Expand Down Expand Up @@ -338,3 +339,6 @@
(if (..< standard value)
(..- value standard)
(..- standard value))))))

(the .public extension
"fraction#")
7 changes: 6 additions & 1 deletion stdlib/source/library/lux/math/number/rational.lux
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
["//" integer (.use "[1]#[0]" base_10)]
["d" decimal]
["[0]" natural (.use "[1]#[0]" base_10)]
["[0]" fraction]
[//
[arithmetic (.only Arithmetic)]
["[0]" unit]]])
Expand Down Expand Up @@ -180,7 +181,8 @@
(the * ..*)
(the / ../)))

(the separator "/")
(the .public separator
fraction.separator)

(the .public (as_text (open "/[0]"))
(text.Injection It)
Expand Down Expand Up @@ -376,3 +378,6 @@
(..- standard)
..absolute
(..< margin_of_error)))))

(the .public extension
"rational#")
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@
phase.Wrapper (Extender <type_vars>) Expander <Platform> Text (Maybe Module)
(//init.Extensions <type_vars>)
(///.Compiler <State> .Module)))
(let [instancer (//init.compiler program global phase_wrapper extender expander syntax.prelude (its #write platform) program_module program_definition
(let [instancer (//init.compiler program global phase_wrapper extender expander .prelude (its #write platform) program_module program_definition
all_extensions)]
(instancer $.key (list))))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
["[0]" dictionary (.only Dictionary)]]]
[math
[number
["n" natural]]]
["n" natural]
["[0]" fraction]
["[0]" rational]]]
["[0]" meta (.only)
["[0]" module]
["[0]" binding]
Expand All @@ -30,7 +32,8 @@
["[0]" code
["?[1]" \\projection (.only Projection)]]
[macro
["^" pattern]]
["^" pattern]
["[0]" template]]
["[0]" type (.only)
["[0]" check]]]]]
["[0]" /// (.only)
Expand Down Expand Up @@ -364,6 +367,25 @@
(.function (_ extension_name phase archive [function_name arg_name body])
(function.function phase function_name arg_name archive body))]))

(template.with [,name ,type ,normal ,numerator_projection ,numerator_analysis]
[(the ,name
(-> Text Handler)
(..custom
[(all ?.and
,numerator_projection
?code.natural)
(.function (_ extension_name phase archive [numerator denominator])
(do phase.monad
[.let [[numerator denominator] (,normal [numerator denominator])]
_ (typeA.inference ,type)
@ meta.location]
(in (analysis.tuple @ (list (,numerator_analysis @ numerator)
(analysis.natural @ denominator))))))]))]

[fraction fraction.Number fraction.normal ?code.natural analysis.natural]
[rational rational.Number rational.normal ?code.integer analysis.integer]
)

(the with_basic_extensions
(-> Bundle
Bundle)
Expand All @@ -375,7 +397,10 @@
(install "global#" ..global)
(install "universe#" ..universe)
(install "when#" ..when)
(install "function#" ..function)))
(install "function#" ..function)

(install fraction.extension ..fraction)
(install rational.extension ..rational)))

(the with_io_extensions
(-> Bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
[target
[jvm
["_" bytecode (.only Label Bytecode) (.use "[1]#[0]" monad)]
["[0]" constant]
[encoding
["[0]" signed (.only S4)]]
["[0]" type (.only Type)
Expand Down Expand Up @@ -375,7 +376,7 @@

parts
(do [! _.monad]
[_ (_.int (.i64 +0))
[_ (_.int (constant.integer (.i64 +0)))
_ (monad.each ! (is (-> (Bytecode Any)
(Bytecode Any))
(function (_ it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
["[0]" modifier (.use "[1]#[0]" monoid)]
["[0]" method (.only Method)]
["[0]" class (.only Class)]
[constant
["[0]" constant (.only)
[pool (.only Resource)]]
[encoding
["[0]" name]]
Expand Down Expand Up @@ -258,7 +258,7 @@
actual
expected
<op>
(_.int (i32.i32 (.i64 <expected>)))
(_.int (constant.integer (i32.i32 (.i64 <expected>))))
(_.if_icmpeq @then)
falseG
(_.goto @end)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
[target
[jvm
["_" bytecode (.only Bytecode)]
["[0]" constant]
["[0]" type]
[encoding
["[0]" signed]]]]]]]]
Expand Down Expand Up @@ -53,7 +54,7 @@
(_.sipush value)

{try.#Failure _}
(_.int (.i64 lefts))))))
(_.int (constant.integer (.i64 lefts)))))))

(the .public (right? right?)
(-> Bit
Expand Down Expand Up @@ -94,10 +95,10 @@
[memberI (phase archive member)]
(in (do _.monad
[_ _.dup
_ (_.int (.i64 idx))
_ (_.int (constant.integer (.i64 idx)))
_ memberI]
_.aastore))))))]
(in (do [! _.monad]
[_ (_.int (.i64 (list.size membersS)))
[_ (_.int (constant.integer (.i64 (list.size membersS))))
_ (_.anewarray //type.value)]
(monad.all ! membersI))))))
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
[target
[jvm
["_" bytecode (.only Label Bytecode) (.use "[1]#[0]" monad)]
["[0]" constant]
["[0]" method (.only Method)]
[constant
[pool (.only Resource)]]
Expand Down Expand Up @@ -56,7 +57,7 @@
(-> Natural
(Bytecode Any))
(all _.composite
(<| _.int .i64 by)
(<| _.int constant.integer .i64 by)
_.iadd))

(the (inputs offset amount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
super_nested_lefts (all _.composite
_.swap
_.isub
(_.int (i32.i32 (.i64 +1)))
(_.int (constant.integer (i32.i32 (.i64 +1))))
_.isub)
super_nested (all _.composite
... lefts, sumT
Expand All @@ -315,7 +315,7 @@
_.astore_0)
update_$lefts (all _.composite
_.isub
(_.int (i32.i32 (.i64 +1)))
(_.int (constant.integer (i32.i32 (.i64 +1))))
_.isub)
again (is (-> Label (Bytecode Any))
(function (_ @)
Expand Down
Loading

0 comments on commit cc09e2f

Please sign in to comment.