This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-11
Channels
- # announcements (21)
- # aws (2)
- # babashka (20)
- # beginners (47)
- # bristol-clojurians (2)
- # calva (63)
- # cider (24)
- # clj-kondo (22)
- # cljs-dev (3)
- # cljsrn (6)
- # clojars (3)
- # clojure (147)
- # clojure-europe (21)
- # clojure-france (2)
- # clojure-italy (3)
- # clojure-losangeles (1)
- # clojure-nl (3)
- # clojure-spec (2)
- # clojure-uk (70)
- # clojurescript (37)
- # core-logic (6)
- # cursive (4)
- # data-science (2)
- # datomic (99)
- # events (1)
- # figwheel-main (20)
- # fulcro (26)
- # graalvm (6)
- # graphql (5)
- # kaocha (8)
- # leiningen (20)
- # meander (22)
- # nrepl (4)
- # off-topic (27)
- # pathom (5)
- # pedestal (3)
- # re-frame (20)
- # reagent (4)
- # shadow-cljs (43)
- # spacemacs (11)
- # tools-deps (55)
- # tree-sitter (6)
- # vim (8)
- # xtdb (18)
- # yada (14)
@connor480 http://clojuredocs.org/clojure.core/map-indexed has some good examples (in general, http://clojuredocs.org will probably be more helpful than just the docstrings alone).
any idea how do I define postgresqls jsonb type in spec.. For example I can define basic types like:
(s/def ::id integer?)
(s/def ::service string?)
(s/def ::application string?)
but if i need to have jsonb type, is there an additional library etc to get that datatype for spec?By default it’ll just come out as a PGobject, but if you’re deserialising it into Clojure data structures it’ll be a map, vector, string, number or bool.
Hi, I'm John. I'm learning Clojure, I really like it to far. I have created two functions for andsimplify and orsimplify which takes a boolean expression like (andsimplify '(and x y false)) and returns the evaluated form, which is false in this case. I want to create a map of some sort to recursively check for each nested expression.
(defn recursive_function
[idealreturn]
:else
(let [letvar (first idealreturn)]
(map recursive_function (rest idealreturn)
(cond (seq? idealreturn) (println "ideal" idealreturn)
(= letvar 'and) (and-simplify idealreturn)
(= letvar 'or) (or-simplify idealreturn)
))
idealreturn))
(defn simplify [expr]
(if-not (seq? expr) expr
(let [[op & args] expr
args (map simplify args)]
(println op)
(condp = op
'and (if (->> args (some false?))
false
expr)
'or (or (->> args (some true?))
expr)
(throw (ex-info "Uknown op" {:op op}))))))
(cleaned up a bit)
(defn simplify [expr]
(if-not (seq? expr) expr
(let [[op & args] expr
args (map simplify args)]
(condp = op
'and (if (some false? args)
false
expr)
'or (or (some true? args)
expr)
(throw (ex-info "Unknown op" {:op op}))))))
This is my pseudocode? Any tips on how to fix it so I can simplify nested expressions like (and true false(and true x y(and true false)) which, in this case would simplify to false. Assume my andsimplify and orsimplify functions work perfectly
I prefer the latter because it reads more like English to me. “(mod x 3) is equal to 0”.
Just as another data point, I prefer the former because it's easier to parse - otherwise we have to mentally close parenthesis to find 0's "level". That's not a problem here, but can be quite annoying on longer examples:
(deftest this
(testing "test"
(is (= (some (long (chain))) 0))))
(deftest this
(testing "test"
(is (= 0 (some (long (chain)))))))
to me the former reads like if (nil == x) {}
in regular languages, which is backward for most people but the idea it was used is to prevent assignments in the if.
I think I've seen the latter version more frequently, but I'm not sure if I like it better.
@spasov you can use zero?
(https://clojuredocs.org/clojure.core/zero_q)
How do you recommend checking if a string is a valid UUID?
(uuid? (java.util.UUID/fromString customer-uuid))
will coerce customer-uuid
into a valid uuid e.g.
05401099-3a50-4987-b978-973
which is invalid is transformed into #uuid "05401099-3a50-4987-b978-000000000973"
and now evaluates to true
. Should I just go with regex?
@slack.jcpsantiago Seems UUID/fromString does its own validation and your example is actually a valid UUID.
weird, so it doesn’t matter how many characters exist between the dashes? because 05-3a50-47-b-973
also evaluates to true
. According to https://www.rfc-editor.org/info/rfc4122 the canonical form should be a total of 36 characters in 8-4-4-4-12 form
going with this instead (re-find #"[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}" potential-uuid-string)
but I’m still curious why fromString
fills the string with zeroes, so it’s always true
There seems to be a bug also: https://bugs.openjdk.java.net/browse/JDK-8202760?attachmentViewMode=list
I have a large collection I may not need to use. Would declaring it with def c (delay coll)
to prevent memory usage? Or how else? It's CLJS
to deliver data later delay still needs it in memory. So it can not save memory
Thanks. I'm thinking about creating an atom instead and a function to populate it instead of def
ing the collection
I'd appreciate suggestions on how to inspect memory as well
delay would help if you had function calls to populate it inside the literal eg. (delay {:a (foo) :b (bar)})
where foo and bar functions return large size data
hi everyone, I am new to Clojure & its been only a week, I am already in love with Clojure, can anyone suggest a small project that I can write to learn/practice in, maybe a small library port or some tool?
You can try creating a Clojure wrapper for some existing Java library. That will be useful for the community as well. Maybe tomlJ? A TOML 0.5 parser.
I personally would suggest doing something you know how to do from other languages. That way, you can focus on implementing it with Clojure instead of trying to wrap your head around how to actually do it.
I personally like doing APIs, because that's something I'm familiar with and I don't really need to think about the specifics of it, just how to achieve what I already know about APIs with Clojure.
Another thing you can try is simple text-based games. Those are always fun. Just keep the scope super small.
Thanks for the reply , I have quite a bit of experience in programming in general, I will try to port some library from python to Clojure
I am not sure should this question belong to off-topic channel? or asking such question is fine here.