Fork me on GitHub

@connor480 has some good examples (in general, will probably be more helpful than just the docstrings alone).

👍 4

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.

Frank Jay12:03:31

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.

Frank Jay13:03:45

(defn recursive_function

    (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)


(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}))))))


a variant with separate or-simplify / and-simplify seems more complex to me, actually


(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}))))))


Do you want something like flatten?

Frank Jay13:03:23

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


Okay, my bad. Now I understand what you want.


This is like a tree of predicates where a node is truthy if all children are truthy.


Is it more idiomatic to write: (= 0 (mod x 3)) or (= (mod x 3) 0)


I prefer the latter because it reads more like English to me. “(mod x 3) is equal to 0”.


Keep in mind there is a zero? predicate.

👍 4

Yup, thanks a lot 🙂


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)))))))

👍 4

Yes I can see how that can be a problem in the first case.


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 also prefer the first. Easy on the eyes.

👍 4

or: (zero? (mod x 3))


I think I've seen the latter version more frequently, but I'm not sure if I like it better.


Beautiful! 🙂


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 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


facepalm ok let’s keep it broken. nice

Lucas Vassalli17:03:41

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

Lucas Vassalli17:03:51

Thanks. I'm thinking about creating an atom instead and a function to populate it instead of defing the collection

Lucas Vassalli17:03:28

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

👍 8

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.


How experienced are you with programming in general?


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.


Fight one battle at a time, so to speak.


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

👍 4

I am not sure should this question belong to off-topic channel? or asking such question is fine here.


I think it's a good channel to ask in. but I don't have any recommendations sorry


Hi all, just joining.

👍 4