clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
Ben Sless 2020-11-28T04:26:37.261500Z

Hey Will :) There's #teknql but he focused more on fibers usage You could also try #java I'll reply to you by email later today, tldr I probably got some stuff wrong. From what I saw it's common to have one ContinuationScope and not open a new one every time

kwrooijen 2020-11-28T09:41:03.263100Z

Anyone know of a library / method to create a hash from a clojure map in both Clojure and Clojurescript? The clojure.core/hash function produces different results (CLJ vs CLJS).

borkdude 2020-11-28T10:03:28.264Z

@kevin.van.rooijen This is another one: https://github.com/arachne-framework/valuehash But I think you will get fundamentally different hashes in CLJ and CLJS due to the host platform. If you want to avoid this, maybe use a stringified cryptographic hash or something?

mpenet 2020-11-28T10:04:56.264600Z

Datahike has a lib for that as well

mpenet 2020-11-28T10:05:00.264800Z

Hasch

borkdude 2020-11-28T10:05:34.265Z

https://github.com/replikativ/hasch

mpenet 2020-11-28T10:05:47.265600Z

That one yes

borkdude 2020-11-28T10:06:58.266500Z

@kevin.van.rooijen What you can also do, if the data structure isn't that rich: encode to bencode and then crypto-hash those bytes, since the bencode representation of a map is always ordered

borkdude 2020-11-28T10:07:06.266700Z

I've seen someone using that trick before

kwrooijen 2020-11-28T10:08:39.267300Z

The datastructure can vary is size. I'm going to look at the hasch library, it seems like it does what I want

borkdude 2020-11-28T10:09:22.268Z

I wasn't talking about size, richness in types (sets, uuids, etc)

kwrooijen 2020-11-28T10:09:28.268200Z

Oh right

kwrooijen 2020-11-28T10:10:16.268600Z

I'll take a look at that option as well 🙂

kwrooijen 2020-11-28T10:10:21.268800Z

Thanks

palo 2020-11-28T14:10:49.271700Z

Hi guys, is there any library for working with timeseries ? Let’s say i have input of random epochs with data sets and want to make different aggregations in time e.g. time-1h, time-3h, time-6h, time-12h … So similar goal than Influx RP (DURATION) 🙂

2020-11-28T14:44:10.271900Z

I've been doing stuff like this lately:

(defn last-rounded-ms [time-ms dur-ms]
  (- time-ms (mod time-ms dur-ms)))

(def series
  (->> 
    (iterate #(+ (rand-int 5000) %) (System/currentTimeMillis))
    (take 100)
    (map (fn [time] {:time time :val (rand)}))))

;;=>
;;{:time 1606574577638, :val 0.4425581456446229}
;;{:time 1606574581828, :val 0.6842765060777032}
;;{:time 1606574583114, :val 0.7802471729760035}

(->> series
     (map (fn [pt]
         (assoc pt :bucket
                (last-rounded-ms (:time pt) (* 60 1000)))))
     (partition-by :bucket))
;;=>
(({:time 1606574505069, :val 0.3325513886871063, :bucket 1606574460000}
  {:time 1606574506946, :val 0.5809867767391736, :bucket 1606574460000}
  {:time 1606574509770, :val 0.09720508907807157, :bucket 1606574460000}
  ...)
 ({:time 1606574520971, :val 0.7242463947216449, :bucket 1606574520000}
  {:time 1606574522158, :val 0.6796656790450822, :bucket 1606574520000}
  {:time 1606574527077, :val 0.26636079563117787, :bucket 1606574520000}
  ...)
 ({:time 1606574581828, :val 0.6842765060777032, :bucket 1606574580000}
  {:time 1606574583114, :val 0.7802471729760035, :bucket 1606574580000}
  {:time 1606574584050, :val 0.3131993783803969, :bucket 1606574580000}
  ...)
 ...)

2020-11-28T14:44:46.272200Z

note the bucketing can also be done as a transducer if you're working with streaming data

2020-11-28T14:50:23.272600Z

The xforms library let's you get pretty fancy with aggregations: https://github.com/cgrand/xforms And it's window-by-time function also is relevant here

Max 2020-11-28T15:27:17.276300Z

I just saw the https://github.com/leonoel/cloroutine and https://github.com/leonoel/missionary libraries go by, both seem like they push Clojure in new and interesting directions. But I’m a newbie, I’m not super familiar with the state of the Clojure ecosystem. I’d be interested in the opinions of those with a little more experience. What do you think?

lilactown 2020-11-28T16:09:32.277300Z

they seem fascinating, potentially useful. I find the syntax pretty inscrutable but that's probably just a lack of familiarity

lilactown 2020-11-28T16:11:51.279Z

I've used core.async and manifold in production, which are similar to cloroutine and missionary. I would love to see a comparison in approaches. It seems like the author is still experimenting, based on the READMEs, so I probably wouldn't use them in production until they stabilized

2020-11-28T16:21:54.279100Z

cloroutine is not really a new idea, in fact it's heavily inspired by core.async 's implementation of go blocks. cloroutine adds some optimizations and provides cloning. missionary is a clojure incarnation of what is currently known as reactive programming (althought I prefer to just call it functional programming), which is quite popular in java/scala but not so much in clojure ecosystem (for now !), possibly because Rich himself expressed some doubts about this paradigm and chose to invest on CSP instead. Compared to e.g RxJava, missionary leverages coroutines instead of monadic composition and aims to fix some legacy weirdness inherent to its internal protocol (now standardized as Reactive Streams). FYI #missionary exists if you want to discuss it further

Max 2020-11-28T17:43:49.282800Z

What interests me about cloroutine is that it seems like it paves a path towards Lisp’s conditions in a way that core.async does not. For example, I don’t know how I’d implement https://github.com/ajnsit/concur using core.async, but I can see a clear path with Cloroutine

Max 2020-11-28T17:56:51.283900Z

Is that impression accurate? It’s very possible I’m missing something

2020-11-28T18:18:48.284400Z

If you want a way to do something with continuations in a language without continuations, you may want to look at the continuation monad

2020-11-28T18:22:29.284600Z

https://blog.mattbierner.com/the-delimited-continuation-monad-in-javascript/ is an example of the cont monad in js (most examples are in haskell), in clojure you can pretty up the syntax a fair bit with macros

2020-11-28T18:46:51.284900Z

all of these concepts are equally powerful, you can basically take any monad instance and write a direct-style syntax on top of it using continuations or coroutines @max.r.rothman here's a case of hijacking of core.async's coroutine engine to implement algebraic effects https://github.com/brandonbloom/cleff

palo 2020-11-28T19:23:22.285300Z

@jjttjj Thx man 🙂 this works great :thumbsup: I’m working on some prototype so this is just enough to present idea (charts), ideally i will deal with RP directly in influx/prometheus later 😉 .. Now the dataset is just raw select from RDBS ..

👍 1
Max 2020-11-28T20:35:50.286200Z

Awesome, thanks!