data structures - Hashcode of function changing inside atom...why is this happening?

As part of a data visualization app that I'm working on, I've encountered something that's either a bizarre bug or me fundamentally not understanding something.My application has code that takes data structures representing colorscales and transforms them into functions that take a number and return a hash of color RGB values.Both gradient and range colorscales are implemented:{:type :gradient :scale [{:bound 0 :r 0 :g 0 :b 0} {:bound 1 :r 255 :g 0 :b 0} {:bound 2 :r 0 :g 255 :b 0}]}{:type :range :scale [{:bound [[< 0]] :r 25...Read more

data structures - Text editor theory

As I'm always dissatisfied with existing editors, a project I always wanted to start is my own text editor. However doing text editing is serious business.Besides analyzing the source code of existing text editors, is there any book or other resource (like academic work) about this topic? I'm interested especially in something that teaches how to handle memory and how to manage text insertion (if you have a 100 MB file and want to add a char at x position, you can't just memmove the huge text block...)....Read more

Standardizing data structures between different platforms

Imagine, for example, you have front-end and back-end applications. They are both written in different technologies, lets say backend is in python using django and front end in typescript using angular. Now there will be some data that will need to be shared between those two. Enums, serialized dictionaries of class instances or names of some fields.Very quickly a problem arises of data structure duplication and possibility of desynchronisation. (E.g. you have to have to exact enums on both platforms)I was wondering are there any "best practice...Read more

How do I compare Data which are Inside a structure?

lets say I have this: (define-struct person (age sex code)) (define-struct subject (person times)) (define P1 (make-subject (make-person 19 'f 'OM29Q) (list 299 194 242 303 243))) (define P2 ...))) (define P3 ...))) ... (define subjects P1 P2 ... )I want to find out the lowest age of a person in the list subjects.I can't figure out how to implement something like this. Can someone help me out?...Read more

data structures - How to find common phrases in a large body of text

I'm working on a project at the moment where I need to pick out the most common phrases in a huge body of text. For example say we have three sentences like the following:The dog jumped over the woman.The dog jumped into the car.The dog jumped up the stairs.From the above example I would want to extract "the dog jumped" as it is the most common phrase in the text. At first I thought, "oh lets use a directed graph [with repeated nodes]":directed graph Apologies, I made a mistake ...Read more

data structures - Idiomatic way to recurse through collections in Clojure

I'm trying to understand what is the idiomatic way in Clojure to recurse through a tree or a list represented by a Clojure list (or another collection type).I could write the following to count the elements in a flat collection (ignore the fact that it's not tail-recursive):(defn length ([xs] (if (nil? (seq xs)) 0 (+ 1 (length (rest xs))))))Now in Scheme or CL all the examples only ever do this over lists, so the idiomatic base case test in those languages would be (nil? xs). In Clojure we'd like this function to work on all co...Read more

data structures - How to iterate nested PersistentArrayMap in Clojure/Script

After executing a query against the db, the return of the fuction is the list of maps:({:id 1 :name "Book 1" :category "Drama"} {:id 2 :name "Book 2" :category "Drama"} {:id 3 :name "Book 3" :category "Poetry"} {:id 4 :name "Book 4" :category "Poetry"} {:id 5 :name "Book 5" :category "Fantasy"} {:id 6 :name "Book 6" :category "Fantasy"} {:id 7 :name "Book 7" :category "Fantasy"} {:id 8 :name "Book 8" :category "Science fiction"} {:id 9 :name "Book 9" :category "Science fiction"} {:id 10 :name "Book 10" :category "Science fiction"} ...)So, I gro...Read more

data structures - Understanding vars in Clojure

I'm fairly new to Clojure and I'm having a difficult time understanding what's happening behind the scenes with the following code:; Associate the symbol 'fruits to the value ["apple" "banana"](def fruits ["apple" "banana"]) ; returns the var #'user/fruits(count fruits) ; returns 2(def fruits ["cherry" "orange" "grapes"]) ; returns the var #'user/fruits(count fruits) ; returns 3Is each "def" form returning a NEW var data structure that's named #'user/fruits?It seems like the symbol 'fruits is bound to a different var after each "def" form - is ...Read more

clojure - What libraries provide persistent data structures?

I've become addicted to Clojure's core data structures. When working in other languages, I try to stay true to their respective idioms, but occasionally, a few persistent data structures are exactly the right solution to the problem.In particular, I'm looking for implementations of Phil Bagwell's vectors and array mapped tries (ie hash maps). Relevant libraries should include sets, queues, and sorted set/map variants for bonus points....Read more

data structures - Using swap! to update a vector of maps in a Clojure(Script) atom

I have an atom holding a vector of maps (example code from c2 library):(def ^:export data (atom [{:metric "Revenue", :units "USD in thousands" :ranges [150 225 300], :measurements [220 270], :markers [250]} {:metric "Profit", :units "%" :ranges [20 25 30], :measurements [21 23], :markers [26]} {:metric "Order Size", :units "USD average" :ranges [350 500 600], :measurements [100 320], :markers [550]} {:metric "New Customers", :units "count" :ranges [1400 2000 2500], :m...Read more

data structures - How to filter vector of maps by multiple keys in Clojure

Assume we have a datastructure like this one:(def data (atom [{:id 1 :first-name "John1" :last-name "Dow1" :age "14"} {:id 2 :first-name "John2" :last-name "Dow2" :age "54"} {:id 3 :first-name "John3" :last-name "Dow3" :age "34"} {:id 4 :first-name "John4" :last-name "Dow4" :age "12"} {:id 5 :first-name "John5" :last-name "Dow5" :age "24"}]))I have learned how to filter it by one key, for example:(defn my-filter [str-input] (filter #(re-find (->> (str str-input) (lo...Read more