This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-19
Channels
- # bangalore-clj (1)
- # beginners (8)
- # boot (102)
- # cider (1)
- # clara (14)
- # cljs-dev (2)
- # cljsrn (2)
- # clojure (49)
- # clojure-poland (3)
- # clojure-russia (4)
- # clojure-serbia (1)
- # clojure-spec (5)
- # clojure-ukraine (1)
- # clojurescript (181)
- # core-async (4)
- # cursive (2)
- # datomic (7)
- # dirac (34)
- # figwheel (3)
- # fulcro (21)
- # hoplon (5)
- # om (1)
- # parinfer (4)
- # planck (27)
- # re-frame (30)
- # reagent (11)
- # rum (6)
- # shadow-cljs (22)
- # spacemacs (4)
- # unrepl (26)
I’m trying to read a json from stdin but I’m having some problems.. I’m using cheshire trying to convert the entry but I’m getting a “JsonEOFException: Unexpected end-of-input” Does anyone tried to do this?
(ns job-queue.core
(:gen-class)
(:require
[job-queue.job-queue-handler :as handler]
[cheshire.core :refer :all]))
(defn handle-json
[json]
(prn "json: " json)
(prn "json decoded: " (decode json true)))
(defn -main
[& args]
(println "Hi, enter the JSON!")
(doseq [in (line-seq (java.io.BufferedReader. *in*))]
(handle-json in)))
I have tried to do with slurp but it doesn’t print anything
(ns job-queue.core
(:gen-class)
(:require
[job-queue.job-queue-handler :as handler]
[cheshire.core :refer :all]))
(defn handle-json
[json]
(prn "json: " json)
(prn "json decoded: " (decode json true)))
(defn -main
[& args]
(println "Hi, enter the JSON!")
(let [in (slurp *in*)]
(handle-json in)))
I suspect slurp
needs and EOF, which it's not getting if you're running just lein run
and typing
This is a common code pattern I use:
(case (:tag obj)
:foo (let [{:keys [a b c]} obj]
...)
:bar (let [{:keys [x y z]} obj]
...)
:cat (let [{:keys [aa dd ff]} obj]
...))
Is there a nice macro to simplify this? basically, I want to 1. dispatch on the :tag field, and 2. do a destructuring bind on keysYou could just use a multimethod
(defn rule->sexp [obj [[tag & vars] & body]]
`[~tag
(let [{:keys ~(vec vars)} ~obj]
~@body)])
(defmacro tdbind [obj & rules]
(let [obj-var (gensym "obj")]
`(let [~obj-var ~obj]
(case (:tag ~obj-var)
~@(mapcat #(rule->sexp obj-var %) rules)))))
(macroexpand-1
'(tdbind (make some obj)
[[:rect x y]
(* x y)]
[[:circle r]
(* r r 3.14)]
[[:triangle a b c]
(assert false "no idea")]))
(comment
(clojure.core/let
[obj9109 (make some obj)]
(clojure.core/case
(:tag obj9109)
:rect
(clojure.core/let [{:keys [x y]} obj9109] (* x y))
:circle
(clojure.core/let [{:keys [r]} obj9109] (* r r 3.14))
:triangle
(clojure.core/let
[{:keys [a b c]} obj9109]
(assert false "no idea")))))
is closer to what . I had in mind 🙂A multimethod would be a lot simpler
(defmulti area :tag) (defmethod area :rect [{:keys [x y]}] (* x y))
cross-posting this link here from #datomic, would appreciate any help https://stackoverflow.com/questions/47373356/query-result-pagination-in-datomic
What's your way of introducing new bindings as you test some conditions? I see that let bindings in cond
was rejected.
https://dev.clojure.org/jira/browse/CLJ-200?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel
https://github.com/Engelberg/better-cond
Hi, how to get the min value's index of a vector? shall i use (let [v [1 2 3 4]] (.indexOf v (apply min v)))
?
Here’s my try, bit verbose; would the use of reduce make it more or less efficient than using ranges?
(let [v [7 2 4 3]]
(reduce-kv
(fn [[min-k min-v] k v]
(if (< v min-v)
[k v]
[min-k min-v]))
[0 (first v)]
v))
Hello everyone. Did anyone of you ever wrote a logging into a clojure application? I am currently building a clojure app with postgresql and one of main features should be activity log. This feature was actualy designed after i wrote a lot of code, so customizing every database action to also make a activity log would be time counsuming and to be honest not very clean solution.
Therefore I am asking if anyone of you know any good clean solution to this? I was thinking about some posgres triggers or stuff like that, but i need to know which user in my application is doing such action
> Did anyone of you ever wrote a logging into a clojure application? I'm confused by the wording
We have appplication where several users perform basic CRUD actions on postgresql database
for example USER A added entity B with name C , or USER D edited entity (fields E F G) with values ( H I J) .. basicaly an activity log
ah got you! interesting feature. sincerely IDK. the Rails equivalent would be https://github.com/airblade/paper_trail which wraps every CRUD action with an object to be persisted, including a whodunnit
column