├── doc └── intro.md ├── .gitignore ├── README.md ├── project.clj ├── CHANGELOG.md ├── test └── clacks │ └── core_test.clj └── src └── clacks └── core.clj /doc/intro.md: -------------------------------------------------------------------------------- 1 | # Introduction to clacks 2 | 3 | TODO: write [great documentation](http://jacobian.org/writing/what-to-write/) 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /classes 3 | /checkouts 4 | pom.xml 5 | pom.xml.asc 6 | *.jar 7 | *.class 8 | /.lein-* 9 | /.nrepl-port 10 | .hgignore 11 | .hg/ 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # clacks 2 | 3 | A Clojure library designed to ... well, that part is up to you. 4 | 5 | ## Usage 6 | 7 | FIXME 8 | 9 | ## License 10 | 11 | Copyright © 2018 FIXME 12 | 13 | Distributed under the Eclipse Public License either version 1.0 or (at 14 | your option) any later version. 15 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject clacks "0.1.0-SNAPSHOT" 2 | :description "A simple encoder/decoder for the Clacks notation" 3 | :url "https://github.com/practicalli/clacks" 4 | :license {:name "Creative Commons Attribution Share-Alike 4.0 International" 5 | :url "https://creativecommons.org"} 6 | :dependencies [[org.clojure/clojure "1.9.0"]]) 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). 3 | 4 | ## [Unreleased] 5 | ### Changed 6 | - Add a new arity to `make-widget-async` to provide a different widget shape. 7 | 8 | ## [0.1.1] - 2018-11-25 9 | ### Changed 10 | - Documentation on how to make the widgets. 11 | 12 | ### Removed 13 | - `make-widget-sync` - we're all async, all the time. 14 | 15 | ### Fixed 16 | - Fixed widget maker to keep working when daylight savings switches over. 17 | 18 | ## 0.1.0 - 2018-11-25 19 | ### Added 20 | - Files from the new template. 21 | - Widget maker public API - `make-widget-sync`. 22 | 23 | [Unreleased]: https://github.com/your-name/clacks/compare/0.1.1...HEAD 24 | [0.1.1]: https://github.com/your-name/clacks/compare/0.1.0...0.1.1 25 | -------------------------------------------------------------------------------- /test/clacks/core_test.clj: -------------------------------------------------------------------------------- 1 | (ns clacks.core-test 2 | (:require [clojure.test :refer :all] 3 | [clacks.core :refer :all])) 4 | 5 | (deftest alphabet-test 6 | (testing "Test the structure of the alphabet" 7 | (is (map? alphabet)) 8 | (is (not 9 | (empty? alphabet)))) 10 | (testing "Test message conversion to Clacks notation" 11 | (is (= ["001010" "010001" "100111"] (message-clacks "bat" alphabet) ))) 12 | (testing "Test clacks message conversion to English message" 13 | (is (= "bat" (clacks-message ["001010" "010001" "100111"] alphabet-inverted) )))) 14 | 15 | 16 | 17 | ;; Suggestions for Tests 18 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 19 | 20 | ;; Test for an alphabet 21 | ;; Test encoding of a character 22 | ;; Test encoding of a word 23 | ;; Test encoding of a whole message 24 | ;; Test decoding of a character 25 | ;; Test decoding of a word 26 | ;; Test decoding of a whole message 27 | -------------------------------------------------------------------------------- /src/clacks/core.clj: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2 | ;; Clacks Messenger system 3 | ;; - Encoder / Decoder for Clacks notation 4 | ;; 5 | ;; A simple library to convert messages to 6 | ;; and from the Clacks notation 7 | ;; Conversion is via the Clacks alphabet 8 | ;; http://jr0cket.co.uk/2016/03/clacks-interpreter-going-postal-at-london-clojure-dojo.html 9 | 10 | (ns clacks.core) 11 | 12 | (def alphabet {"a" "010001" 13 | "b" "001010" 14 | "t" "100111"}) 15 | 16 | (def alphabet-inverted (clojure.set/map-invert alphabet)) 17 | 18 | 19 | (defn message-clacks 20 | "Converts a message to the Clacks notation" 21 | [message alphabet] 22 | (map 23 | (fn [character] 24 | (get alphabet (str character))) 25 | message)) 26 | 27 | (defn clacks-message 28 | "Converts a collection of Clacks notations to message using the alphabet" 29 | [clacks alphabet] 30 | (reduce 31 | str 32 | (map 33 | (fn [clack] 34 | (get alphabet clack)) 35 | clacks))) 36 | 37 | 38 | 39 | ;; REPL Experiments 40 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 41 | 42 | #_(character-clacks "b") 43 | 44 | #_(map character-clacks "bat") 45 | 46 | #_(message-clacks "bat" alphabet) 47 | 48 | ;; strings are not equal to its character 49 | #_(= "a" \b) 50 | 51 | 52 | 53 | ;; Initial design 54 | ;; Adds complexity of converting between char and keyword 55 | #_(def alphabet {:a "010001" 56 | :b "001010" 57 | :t "100111"}) 58 | 59 | #_(character-clacks :a) 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | ;; Previous experiments 80 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 81 | 82 | ;; (ns htt-clacks.core 83 | ;; (:require [htt-clacks.clacks-alphabet :refer [alphabet]])) 84 | 85 | 86 | ;; Swap keys and values in a map 87 | ;; (def alphabet-inverted (clojure.set/map-invert alphabet)) 88 | 89 | 90 | ;; ;; Convert a character to a binary code 91 | 92 | ;; (defn character->clack [char alphabet] 93 | ;; (let [character (str char)] 94 | ;; (get alphabet character))) 95 | 96 | ;; (character->clack "a" alphabet) 97 | 98 | ;; ;; Convert a string to a binary code 99 | 100 | ;; (defn message->clacks [message alphabet] 101 | ;; (map #(character->clack % alphabet) message)) 102 | 103 | ;; (message->clacks "cab" alphabet) 104 | ;; ;; => ([0 1 1 0 0 0 1 1] [0 1 1 0 0 0 0 1] [0 1 1 0 0 0 1 0]) 105 | 106 | ;; (message->clacks "cab cab" alphabet) 107 | ;; ;; => ([0 1 1 0 0 0 1 1] [0 1 1 0 0 0 0 1] [0 1 1 0 0 0 1 0] [0 0 0 0 0 0 0 0] [0 1 1 0 0 0 1 1] [0 1 1 0 0 0 0 1] [0 1 1 0 0 0 1 0]) 108 | 109 | ;; ;; Create a charater from a clack code 110 | 111 | ;; #_(defn clack->character [clack alphabet] 112 | ;; (get (clojure.set/map-invert alphabet) clack)) 113 | 114 | ;; (defn clack->character [clack alphabet] 115 | ;; (get alphabet-inverted clack)) 116 | 117 | ;; ;; Create a clacks code back to a message 118 | 119 | ;; (defn clacks->message [clacks alphabet] 120 | ;; (reduce str (map #(clack->character % alphabet) clacks))) 121 | 122 | ;; ;; test data 123 | ;; (clacks->message '([0 1 1 0 0 0 1 1] [0 1 1 0 0 0 0 1] [0 1 1 0 0 0 1 0]) alphabet) 124 | 125 | ;; (clacks->message 126 | ;; '([0 1 1 0 0 0 1 1] [0 1 1 0 0 0 0 1] [0 1 1 0 0 0 1 0] [0 0 0 0 0 0 0 0] [0 1 1 0 0 0 1 1] [0 1 1 0 0 0 0 1] [0 1 1 0 0 0 1 0]) alphabet) 127 | 128 | ;; ;; (map str ["c" "a" "b"]) 129 | ;; ;; (reduce str ["c" "a" "b"]) 130 | --------------------------------------------------------------------------------