clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
2020-11-06T00:12:07.166900Z

I could spell out the math as well in the initial date creation time. which feels like reinventing the library

2020-11-06T00:12:17.167100Z

and likely to mess up leap seconds

2020-11-06T01:12:31.172Z

What's people's thoughts on extending nil to support qualifications. For example, imagine you could do: nil/missing-key or nil/file-not-found These would all be treated as a standard nil except there'd also be a function to get the qualified part as a keyword so you could possibly branch on it if you wanted. Also, it would print with the qualification so the programmer can understand the reason for the nil. And I'm imagining they'd get interned, so two nil/missing-key would be equal.

πŸ‘Ž 1
2020-11-06T08:06:15.177300Z

I'm not thinking of overloading it. Nil would still be nil and behave like nil. But it provide a qualification that can let you specify what was nil.

2020-11-06T08:09:20.177500Z

Ya, the performance interop is interesting. But Clojure allows you extend nil with protocols, so I'm assuming it already has some facilities? But maybe won't work for something that need seperate instances of nil.

2020-11-06T08:12:32.177700Z

The idea for example, when you call (get map :key), now both of those return nil: `(get {} :key) (get {:key nil} :key)` So for example, with qualified nils, the former could return: nil/missing-key and the latter just nil

phronmophobic 2020-11-06T08:32:52.178400Z

what you're proposing is still an aggregate value of nil and a qualification or meta data on a nil value. clojure already has a way to describe aggregate values: vectors, sets, and maps. metadata seems like a more appropriate way to do what you're describing, but it's not available and I'm pretty sure it's for performance and due to the limitations imposed by interop with java.

2020-11-06T22:48:18.188500Z

Ya, meta-data would work as well. Ya, the performance implication and interop are a good point in terms of feasability for Clojure

2020-11-06T22:48:48.188700Z

Unless it could be handled at compile time, but I don't think it has the information, or that this feature is important enough for it

phronmophobic 2020-11-06T01:18:16.173Z

overloading null and falsey values is common mistake in other languages/systems/databases. I think using some other alternative would be more appropriate. (eg. [nil :missing-key] over nil/missing-key)

seancorfield 2020-11-06T01:29:12.173400Z

Also nil is currently the underlying Java null (and JavaScript null I assume?) so you'd have to deal with all the conversion back and forth between a native host value and the "metadata" you wanted to attach -- which could be horrendous from a performance p.o.v.

βž• 2
suren 2020-11-06T03:55:57.176100Z

Hi guys, for past few months I have been playing with Clojure and Clojurescript. Its been really fun. Along the way I have created few packages that suits my need. Please check them out. Feedbacks are welcome. https://github.com/ludbek/sql-compose https://github.com/ludbek/validator

πŸ‘ 1
Ivan Fedorov 2020-11-06T13:57:26.179800Z

Is there a bridge from Clojure to Moldable Development? http://youtube.com/watch?v=Pot9GnHFOVU

markaddleman 2020-11-06T16:38:29.181700Z

Given a multimethod and its arguments, how can I obtain the result of the dispatch fn? This would be useful for logging purposes

🀘 1
vncz 2020-11-06T16:41:19.181900Z

That's something I'd also be interested.

markaddleman 2020-11-06T16:57:44.182100Z

It turns out that multimethod functions are defined in Java space have have a public dispatchFn field. So, it looks like calling (.dispatchFn -multimethod-) does the trick

markaddleman 2020-11-06T16:58:17.182300Z

It returns the dispatch function itself so we can invoke the dispatch fn on the args to get the dispatch value

martinklepsch 2020-11-06T17:47:08.185700Z

I’m trying to implement a version of the change-making problem in Clojure with the twist that I’d like to actually have all possible change-combinations returned instead of just the number of different combinations. I found this https://stackoverflow.com/questions/41806819/find-all-combinations-of-a-given-set-of-integers-summing-up-to-a-given-sum but the Haskell and Python solutions make me feel like a terrible imposter πŸ™ˆ If anyone feels like adding a Clojure answer (or helping me come up with one) I’d be very thankful πŸ™‚

martinklepsch 2020-11-06T17:49:24.185900Z

The Python answer is probably not very Clojure-y but the Haskell answer seems like it might be somewhat translateable:

partitions 0 xs = [[]]
partitions _ [] = []
partitions n (xxs@(x:xs)) | n < 0 = []
                          | otherwise = (map (x:) (partitions (n-x) xxs)) ++ partitions n xs

martinklepsch 2020-11-06T17:50:01.186200Z

The piece I don’t quite understand is this I think:

(map (x:) (partitions (n-x) xxs))

2020-11-06T18:09:55.186400Z

It means find all way to get sum (n-x) form list. And for returned list prepend x to it

martinklepsch 2020-11-06T18:12:39.186700Z

ah cool, the (x:) wasn’t quite clear to me but prepending makes sense

2020-11-06T18:13:38.186900Z

It is haskell version of cons sort of

martinklepsch 2020-11-06T18:16:00.187100Z

(defn partitions [n [x & xs :as xxs]]
     (cond
      (zero? n) [()]
      (empty? xxs) ()
      (neg? n) ()
      :else (concat (mapv #(conj % x) (partitions (- n x) xxs))
                    (partitions n xs)) ))

   (partitions 10 [3 4 5])

martinklepsch 2020-11-06T18:16:01.187300Z

nice

martinklepsch 2020-11-06T18:16:16.187500Z

thank you @rdivyanshu, that was the pointers I needed πŸ™‚

πŸ‘ 1
vncz 2020-11-06T19:29:34.188Z

Seems a lot of hassle, but it is something. Thanks for the pointer!

Matias Francisco Hernandez Arellano 2020-11-06T23:07:31.193700Z

Hey Clojurians. I was able to succesful speak at a meetup with a tan "Clojure 101 for Javascripters" and ea good! Ends with a video/live coding (http://egghead.io style) about building a web server with httpkit and compojure. Now I was invited to another meetup but same talk and I want to give some spin to the content. One thing I miss in the first time was a real example of using the repl (I'm new to Clojure too but less new that the audience) and now I'm thinking in a good example of repl driving development. Do you think that just continue with the server example, run the server un the repl and dinamically add a new route to it will be a good example?

πŸ‘ 1