> > Looking at the "(defn register [...])" example. Where is the problem with > the first solution? It doesn't have the bugs the other implementations have > and is extremely simple to reason about? The other two solutions do the > exact same thing just slower with absolutely no gain. If you need the > "status" abstraction use a real state machine. Don't write a recursive > function when you don't have to. The code should never be at a point where > it can be called with forged data and directly skip over the :create and > :check-unqiue states which is possible in 2 of the 3 solutions. >
It bothered me as well that register could skip states. I couldn't figure out how to deal with that and resorted to making the function private :( . I was originally thinking - the sum of the all steps being the variant/sum-type and each step being one of the cases of the variant. However as you said, a state machine might be a better representation. Maybe this was a bad use case for variants. The output of the state machine steps could be a variant over :ok, :err. Either way lets ignore this usage. (def Recipient > (s/either PlaceHolder > Existing > OneOff)) > This looks interesting. Where would I actually use this? I mean, if I have created three records, I may as well implement multi methods or protocols, right? Even if I don't do those, I will still need to use `(condp instance? obj ...)` or equivalent to select the appropriate branch for processing. Is there a way I can use Recipient to select a branch? I am not proposing the variant vector to be used in place of records. I am looking at it as an improvement over using a hashmap containing a :type key. For some reason I am wary of records. The variant vector seemed like a good intermediate solution. On Monday, 7 September 2015 17:13:53 UTC+5:30, Thomas Heller wrote: > > > >> -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.