This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-21
Channels
- # announcements (2)
- # aws (1)
- # beginners (172)
- # boot (3)
- # calva (19)
- # cider (18)
- # clj-kondo (5)
- # cljsrn (18)
- # clojure (47)
- # clojure-europe (9)
- # clojure-finland (7)
- # clojure-italy (3)
- # clojure-nl (15)
- # clojure-spec (20)
- # clojure-sweden (2)
- # clojure-uk (72)
- # clojurescript (45)
- # cursive (42)
- # datomic (6)
- # duct (4)
- # emacs (4)
- # expound (48)
- # figwheel-main (7)
- # fulcro (64)
- # graphql (8)
- # hoplon (9)
- # hyperfiddle (1)
- # jackdaw (8)
- # jobs (4)
- # jobs-discuss (61)
- # klipse (5)
- # leiningen (6)
- # off-topic (72)
- # pathom (2)
- # planck (11)
- # re-frame (1)
- # reagent (3)
- # reitit (16)
- # remote-jobs (17)
- # ring-swagger (3)
- # shadow-cljs (49)
- # spacemacs (12)
- # sql (3)
- # tools-deps (124)
- # vim (64)
- # xtdb (4)
I'm trying to get the duration of some mp3 files, anyone around that can point me in the right direction for doing that with clojure?
there's a java sound api in the JDK, googled: https://stackoverflow.com/questions/3009908/how-do-i-get-a-sound-files-total-time-in-java
Yeah thats what I came across as well. Looks like thats what I'll be going with, thanks
There is some static clojure parser, that support reader macros, reader-eval and maybe read some "unreadble" things like #object[...]
in what way do LispReader.java or tools.reader not satisfy the bill?
(LispReader/read (new PushbackReader (io/reader (.getBytes "[#=(prn :ok)]"))) {})
;; -- expected
;; => [#reader-eval (prn :ok)]
;; -- actual
;; :ok ;; printed
;; => [nil]
well then, no that doesn't exist afaik :)
depending on how desperate you are
user=> (require '[clojure.tools.reader :as r])
nil
user=> (defrecord reader-eval [v])
user.reader-eval
user=> (with-redefs-fn {#'r/read-eval (fn [rdr _ opts pending-forms] (reader-eval. (#'r/read* rdr true nil opts pending-forms)))} #(r/read-string "[#=(prn 1)]"))
[#user.reader-eval{:v (prn 1)}]
(binding [clojure.tools.reader/*default-data-reader-fn* (fn [tag value]
{:tag tag :value value})]
(with-redefs [clojure.tools.reader/read-eval (fn [rdr _ opts pending-forms]
(#'clojure.tools.reader/read* rdr true nil opts pending-forms))]
(clojure.tools.reader/read-string
{:read-cond :preserve}
"[#=(prn :ok) #?@(:clj [1] :cljs [2]) #object[] ::foo]")))
I think that I will use tools.readerJust need to figure out how to "patch" ::foo/bar
to return something like #namespaced-keyword [foo :bar]
the resolver is pluggable, so you can do that
well, maybe not that pluggable
yeah you're out of luck for that unless you redef https://github.com/clojure/tools.reader/blob/master/src/main/clojure/clojure/tools/reader.clj#L343-L361
not quite sure what a good pluggable mechanism for this would be that avoids exposing the entirety of read-keyword
I think that I found a bug
(clojure.tools.reader/read-string
{:read-cond :allow}
"[#?(:cljs #=(prn :ok) :default 1)]")
don't you want :read-cond :preserve ?
well, maybe I'm ahead of you - what do you get and what do you want?
ATM I'm just playing and understanding how clojure.tools.reader
works
Then I see that reader-eval occur in all reader-cond branches
I’m looking for design advice on a feature. I’m writing some code which hits a REST API. The interface to that API exposes some abstractions like “tags”, which are strings. I want to my code to hide those strings behind a mapping, so that the caller of my namespace can pass in data (which I could spec) which will be replaced with the correct string before calling the HTTP endpoint. For abstracting over the tags, should I be using … vars? I could write a namespace that just defs each string and have the caller pass those as arguments. Or maybe just normal keywords, instead? Maintaining a mapping of keyword to string for the tags. Do namespaced keywords make sense here?
the thing is they’re kind of all over the place — they’re tags on some products. So the punctuation and casing and whitespace is inconsistent. I was hoping to design so the caller doesn’t have to know if the “christmas” tag is “Christmas” or “XMAS” or whatever, they can just say tags/christmas
or :christmas
plus then if the tag itself changes, which is fairly likely to happen (maybe there is an effort to make them more consistent), I can change the value in one spot instead of searching for all occurrences
I have timeseries data that is a collection of events. the data is sparse, that is for certain timeframes there are no events. how am I supposed to build on this? do I let the collection with a lot of nil propagate through the system and put nilchecks everywhere? or should I treat the whole timeseries data as a function of time?
maybe a sorted set, sorted by timestamp? that makes grabbing all items between times X and Y cheap
while avoiding any need for keys with nil values
(cmd)user=> (sorted-set-by #(compare (:t %1) (:t %2)) {:t 0 :a 12} {:t 1 :a 3} {:t 4 :a 0} {:t 8 :a 1})
#{{:t 0, :a 12} {:t 1, :a 3} {:t 4, :a 0} {:t 8, :a 1}}
(cmd)user=> (def s *1)
#'user/s
(cmd)user=> (subseq s > {:t 0} < {:t 5})
({:t 1, :a 3} {:t 4, :a 0})
the first arg to sorted-set-by needs to be a comparator of two events
subseq takes the sorted set, and two comparison functions / compared item pairs (it can also take a single pair)
instead of saying "what's the data at time t" you'd say "what are the known data points between t and t'"
you can do the same with a sorted-map with timestamps as keys
like, in general, if I had a time series of data it would just be a collection of events, and any time period where there were no events, well there just wouldn't be events from that time period in the collection
if you need to reify your notion of time periods, then you have a set of time periods, and each event refers to a timeperiod, so a time period with no events would be added to the set of time periods, but have not events referencing it