This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-12
Channels
- # aleph (1)
- # beginners (81)
- # boot (20)
- # cider (46)
- # cljs-dev (6)
- # cljsjs (6)
- # cljsrn (8)
- # clojars (2)
- # clojure (104)
- # clojure-berlin (3)
- # clojure-italy (4)
- # clojure-losangeles (2)
- # clojure-nl (16)
- # clojure-spec (16)
- # clojure-uk (28)
- # clojurescript (88)
- # core-logic (31)
- # cursive (8)
- # data-science (3)
- # datascript (1)
- # datomic (95)
- # docs (1)
- # emacs (6)
- # figwheel-main (24)
- # fulcro (106)
- # graphql (5)
- # hyperfiddle (2)
- # midje (2)
- # nrepl (1)
- # off-topic (14)
- # om-next (1)
- # parinfer (2)
- # pedestal (26)
- # portkey (2)
- # re-frame (11)
- # reagent (27)
- # ring (6)
- # rum (4)
- # shadow-cljs (33)
- # spacemacs (10)
- # specter (53)
- # tools-deps (17)
- # vim (31)
I’ve never seen a deref
used like this before. What does it mean?
@(def sample-data
(->> (for [color colors size sizes type types]
{:inv/color color
:inv/size size
:inv/type type})
(map-indexed
(fn [idx map]
(assoc map :inv/sku (str "SKU-" idx))))
vec))
the def returns a var, and deref, when applied to a var, "returns its current state"- so say the docs.
so it will return the results of- constructing a list of :inv/color :inv/size :inv/type maps, passed through map-indexed, and then turned into a vec
@jonahbenton Ah, I see, thank you. So instead of returning #'some.ns/sample-data
it’ll return the the contents of it.
yeah, definitely an opaque formulation for clj, though it feels idiomatic for something, but I can't place it. maybe scala is where i remember seeing phrases like that. I would guess it was written by someone working in a functional-but-not-immutable mindset.
I encountered it in the Datomic tutorial: https://docs.datomic.com/cloud/tutorial/assertion.html#sec-5
Does anyone have a solution to the way cljfmt
indents cond (I prefer the tests and expressions to be indented differently)? I have an elisp rule for cider, but I'm trying to create the same rule for those that don't use emacs.
Nope 😞
This is the formatting I find much easier to read:
(cond
t1
e1
t2
e2)
@didibus (compile ...) of a namespace with gen-class doesn't produce .class files?
does anyone know of any really good functional cookbooks or resources for working with really multidimensional nested data?
I'm basically forming compound keys for vertical and horizontal subslices of multidimensional data and I feel like a fool. I can't do my normal pipeline approach because I have to map over the thing I'm mapping over the thing I'm mapping over 😩
I'm trying to string together some crazy apply map comp
stuff, and I get the distinct feeling this is like a rubiks cube that I don't know the patterns for
are you aware of Specter? sounds like it might help with that https://github.com/nathanmarz/specter
in this particular instance, it's because I'm working with hiccup. But in general I've hit these kinds of problems before and I feel like I need to find the spirit of Peter Norvig
as for your question, this is great but you may find it slow going at the beginning, depending on your background: http://www.ccs.neu.edu/home/matthias/HtDP2e/
skim part five to get a feel about whether this is what you're looking for: http://www.ccs.neu.edu/home/matthias/HtDP2e/part_five.html
the "Design of Computer Programs" that Peter Norvig teaches on Udacity is one of the best things I've ever done for my professional career
(def data-1 `{(a 1) :c})
(type (first (keys data-1)))
;; => clojure.lang.Cons
(def data-2 {(list `a 1) :c})
(type (first (keys data-2)))
;; => clojure.lang.PersistentList
how do I convert nested data with clojure.lang.Cons
in it (like data-1) to normal one (like data-2)?
if your code relies on the difference between cons and list, that is usually a problem with your code
What is your usecase? Things like Cons
and PersistentList
should usually be an implementation detail.
If you need a predicate to check for a list, I did a take on this some time ago: http://bytopia.org/2016/03/08/what-is-a-list/
@noisesmith @alexyakushev I need to validate some data with clojure.spec, but it says the data in data-1 is invalid while data-2 is ok
does your spec use list? if so, don't
list? is pretty much never useful
I wrote the spec
Then you've probably used a check for list?
there somewhere where you shoud've used seq?
hmm, looks like the problem is not with the spec I wrote, but with the spec from a library I use which is a bit complex
@noisesmith @alexyakushev I'd rather stick to a solution to the question I originally asked: how to convert such nested data
update-in with list*
but it's a sign of a bad spec, it shouldn't care about the difference between a cons and a list
it can be in arbitrary shape
then clojure.walk/post-walk with seq? and list*
so no update-in
it's still a lot of effort to accomodate a bad design
okay, I'll try
thanks a lot
Where can I find the method that turns java.util.Date
into "2018-01-01T00:00:00.000-00:00"
string?
it's defined with the reader tags if you mean the one that has #inst right before it
https://github.com/clojure/clojure/blob/e19157c4809622fcaac1d8ccca8e3f6a67b3d848/src/clj/clojure/instant.clj#L176 There is a really odd code due a bug on JVM 1.4 (?!) I will use
(-> (doto (new SimpleDateFormat "yyyy-MM-dd'T'HH:mm:ss.SSS-00:00")
(.setTimeZone (TimeZone/getTimeZone "GMT")))
(.format #inst"2018"))
I’d like to send two different queries at the same time, and get both result sets back in one network round trip
(require '[clojure.spec.alpha :as s])
(s/valid? int? 1) ;=> true
(s/valid? #(= 1 %) 1) ;=> true
(s/exercise int? 1) ;=> ([0 0])
;; ???
(s/exercise #(= 1 %) 1) ;; Spec assertion failed. Spec: nil Value: nil
@joefromct let’s say querying 2 different foreign keys from the same id
https://github.com/clojure/clojure/blob/e19157c4809622fcaac1d8ccca8e3f6a67b3d848/src/clj/clojure/instant.clj#L176 There is a really odd code due a bug on JVM 1.4 (?!) I will use
(-> (doto (new SimpleDateFormat "yyyy-MM-dd'T'HH:mm:ss.SSS-00:00")
(.setTimeZone (TimeZone/getTimeZone "GMT")))
(.format #inst"2018"))
hey @arohner that's usually a wire protocol capability of the underlying database. you can, for instance, send multiple queries over the wire using the mysql protocol, but it's often disabled because it can be used for sql injection
when you brew install clojure
it installs java for you right?
not in my experience
I don't think (not sure) postgres lets you fire multiple quiries delimited by ;
if i remember correctly... sorta feels like bad form anyway (with params epsecially...?)
but if you have a table with an id and then two columns that are fks into their own lookup tables, you can get the data from the lookup tables with a single statement/join
ok i might be missing it but whats wrong with this? probably not at the same time right... ?
(let [seq-1 (j/query "select from table_one")
seq-2 (j/query "select from fk_table") ]
...
)
once you have a connection pool, the overhead per-query is small. there's only so much you can fit into a packet.
I’m more worried about latency of waiting for query 1 to finish before issuing query 2
@arohner you should ask it in #sql
btw i'm also interested in this question, as it can be helpful for my sql library which makes joining and filtering tables a breeze https://github.com/walkable-server/walkable
walkable needs more work before it reaches 1.0 release
but at least it works now
if you have any problems, or find something hard to express with walkable, do tell me in #walkable
early adopters are hugely welcome 🙂 @arohner
yeah unless the db is super slow... maybe table_one
is a view/aggregate over 15 million rows
yeah, agree ^^- all drivers will allow for true parallel communication
j/query
is greedy too, so i've been using a lot of j/reducible-query
lately, but if your results fit into memory no worries
think you need to provide a generator
a raw predicate function like #(= 1 %) doesn't have a generator attached, and spec needs a generator to exercise the spec
spec internally has a list of a lot of predicates from clojure.core that it implicitly has a generator for, like clojure.core/int?
@joefromct what version are you running? I see: