Skip to content

Commit

Permalink
Added machinery for numeric digits.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Jul 9, 2024
1 parent f5c14a3 commit 6913ed8
Show file tree
Hide file tree
Showing 10 changed files with 975 additions and 292 deletions.
2 changes: 1 addition & 1 deletion documentation/bookmark/web_browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
0. https://github.com/wexond/wexond
0. http://next.atlas.engineer
0. https://workona.com/
0. https://luakit.github.io/
0. [luakit: A fast, extensible, and customizable web browser](https://luakit.github.io/)
0. https://www.thurrott.com/cloud/web-browsers/204669/opera-web-browser-is-reborn

# Security
Expand Down
110 changes: 110 additions & 0 deletions stdlib/source/library/lux/math/number/digit.lux
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
... 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/.

(.using
[library
[lux (.except)
[function
[predicate (.only Predicate)]]]])

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

... https://en.wikipedia.org/wiki/Numerical_digit
(every .public Digit
(Record
[#character Text
#value Natural]))

(with_template [,character ,value ,name ,name']
[(the ,name'
,character)

(the .public ,name
Digit
[#character ,character
#value ,value])]

["0" 00 the_00 the_00']
["1" 01 the_01 the_01']

["2" 02 the_02 the_02']
["3" 03 the_03 the_03']
["4" 04 the_04 the_04']
["5" 05 the_05 the_05']
["6" 06 the_06 the_06']
["7" 07 the_07 the_07']

["8" 08 the_08 the_08']
["9" 09 the_09 the_09']

["A" 10 the_10 the_10']
["B" 11 the_11 the_11']
["C" 12 the_12 the_12']
["D" 13 the_13 the_13']
["E" 14 the_14 the_14']
["F" 15 the_15 the_15']
)

(the .public (base_02? it)
(Predicate Text)
(`` (when it
(,, (with_template [,digit]
[,digit
true]

[..the_00']
[..the_01']
))

else
false)))

(the .public (base_08? it)
(Predicate Text)
(`` (when it
(,, (with_template [,digit]
[,digit
true]

[..the_02']
[..the_03']
[..the_04']
[..the_05']
[..the_06']
[..the_07']
))

else
(base_02? it))))

(the .public (base_10? it)
(Predicate Text)
(`` (when it
(,, (with_template [,digit]
[,digit
true]

[..the_08']
[..the_09']
))

else
(base_08? it))))

(the .public (base_16? it)
(Predicate Text)
(`` (when it
(,, (with_template [,digit]
[,digit
true]

[..the_10']
[..the_11']
[..the_12']
[..the_13']
[..the_14']
[..the_15']
))

else
(base_10? it))))
65 changes: 41 additions & 24 deletions stdlib/source/library/lux/math/number/i64.lux
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@
(n.* ..bits_per_byte
..bytes_per_i64))

... TODO: Do some form of type specialization.
(every .public Shift
Natural)

(the .public shift
(-> Natural
Shift)
(n.% ..width))

(the .public (opposite it)
(Change Shift)
(n.- it ..width))

(with_template [<parameter_type> <name> <op>]
[(the .public (<name> parameter subject)
(for_any (_ it)
Expand All @@ -42,16 +55,19 @@
[(I64 Any) xor .i64_xor#]
[(I64 Any) and .i64_and#]

[Natural left_shifted .i64_left#]
[Natural right_shifted .i64_right#]
[Shift left_shifted .i64_left#]
[Shift right_shifted .i64_right#]
)

... https://en.wikipedia.org/wiki/Mask_(computing)
(every .public Mask
I64)

(every .public Address
Natural)

(the .public (bit position)
(-> Natural
(-> Address
Mask)
(|> 1 .i64 (..left_shifted (n.% ..width position))))

Expand All @@ -61,8 +77,7 @@

(the .public not
(for_any (_ it)
(-> (I64 it)
(I64 it)))
(Change (I64 it)))
(..xor (.i64 (-- 0))))

(the .public false
Expand All @@ -83,8 +98,8 @@
bits (|> 1 .i64 (..left_shifted (n.% ..width bits)) .--))))

(the (with_shift shift value)
(-> Natural Natural
Natural)
(-> Shift
(Change Natural))
(|> value
(right_shifted shift)
(n.+ value)))
Expand All @@ -104,47 +119,51 @@

(the .public (zero index input)
(for_any (_ it)
(-> Natural (I64 it)
(I64 it)))
(-> Address
(Change (I64 it))))
(|> index ..bit ..not (..and input)))

(with_template [<name> <op>]
[(the .public (<name> index input)
(for_any (_ it)
(-> Natural (I64 it)
(I64 it)))
(-> Address
(Change (I64 it))))
(|> index ..bit (<op> input)))]

[one ..or]
[flipped ..xor]
)

(the .public (zero? index input)
(-> Natural
(-> Address
(Predicate (I64 Any)))
(|> (.i64 input)
(..and (..bit index))
(n.= 0)))

(the .public (one? index input)
(-> Natural
(-> Address
(Predicate (I64 Any)))
(.not (..zero? index input)))

(every .public Rotation
Shift)

(with_template [<name> <forward> <backward>]
[(the .public (<name> distance input)
(for_any (_ it)
(-> Natural (I64 it)
(I64 it)))
(..or (<forward> distance input)
(<backward> (n.- (n.% ..width distance) ..width) input)))]
(-> Rotation
(Change (I64 it))))
(let [distance (shift distance)]
(..or (<forward> distance input)
(<backward> (opposite distance) input))))]

[left_rotated ..left_shifted ..right_shifted]
[right_rotated ..right_shifted ..left_shifted]
)

(the .public (region offset size)
(-> Natural Natural
(-> Rotation Natural
Mask)
(..left_rotated offset (..mask size)))

Expand Down Expand Up @@ -180,16 +199,14 @@

(the .public reversed
(for_any (_ it)
(-> (I64 it)
(I64 it)))
(Change (I64 it)))
(let [swapper (is (-> Natural
(for_any (_ it)
(-> (I64 it)
(I64 it))))
(Change (I64 it))))
(function (_ power)
(let [size (..left_shifted power 1)
repetitions (is (-> Natural Text
Text)
repetitions (is (-> Natural
(Change Text))
(function (_ times character)
(loop (again [iterations 1
output character])
Expand Down
Loading

0 comments on commit 6913ed8

Please sign in to comment.