Fork me on GitHub

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.

👎 3

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)


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.


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.


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.


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


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.


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


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


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.

👍 3
Ivan Fedorov13:11:26

Is there a bridge from Clojure to Moldable Development?


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

metal 3

That's something I'd also be interested.


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


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


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


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


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 ([email protected](x:xs)) | n < 0 = []
                          | otherwise = (map (x:) (partitions (n-x) xxs)) ++ partitions n xs


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

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


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


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


It is haskell version of cons sort of


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

   (partitions 10 [3 4 5])


thank you @U0666D1EK, that was the pointers I needed 🙂

👍 3
Matias Francisco Hernandez Arellano23:11:31

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

👍 3