Created
June 19, 2016 04:56
-
-
Save timmc/b4db7d988121d9f769c2c40f408dfa22 to your computer and use it in GitHub Desktop.
Incomplete implementation of conversion to binary in swearjure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Still needs assoc translated... everything else is trivial. | |
(defn to-bits | |
"Yield a map of place indexes to bit values as booleans. Why a map | |
instead of a vector? Because I can't safely address beyond the end of | |
a vector when carrying to a new place value." | |
[n] | |
(#(((% 1) :main) %) | |
[n | |
{:main #(((% 1) :count-up) [(% 0) (% 1) 0 {0 false}]), | |
;; Given an array of bits in ascending order and a place offset, | |
;; add 1 to the represented number. | |
:add1 #(if ((% 2) (% 3) false) | |
;; Flip the current bit and add1 in the next place | |
(((% 1) :add1) [(% 0) (% 1) | |
;; TODO assoc in quasi-swearjure | |
;; (build off of hypirion's hash-map impl) | |
(assoc (% 2) (% 3) false) | |
(inc (% 3))]) | |
;; May append | |
(assoc (% 2) (% 3) true)) | |
:count-up #(if (= (% 0) (% 2)) | |
(% 3) | |
(((% 1) :count-up) [(% 0) (% 1) | |
(inc (% 2)) | |
(((% 1) :add1) [(% 0) (% 1) | |
(% 3) | |
0])]))}])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment