It's nice if the function returns the same sort of data as it consumes, because then it's easy to repeat it with `iterate` or `reduce`. So, if you take your first example, then you could write:
(take 100 (iterate (partial progress-state markov-model) initial-state)) to get the next 100 states. If the process takes information at each step, e.g.: (progress-state-with-input markov-model-2 previous-state current-input) -> new-state then you can do a similar thing with reduce: (take 100 (reductions (partial progress-state-with-input markov-model-2) initial-state inputs)) I'd prefer that to your second approach, as I don't think there's much reason to bundle the process and its state. Another question to ponder is whether there should be a progress-state function, or whether the model itself could be a function. If the mechanics of the process are somewhat generic, and the `markov-model` is just data, then it's good as it is. But I'd make sure that progress-state isn't just an empty wrapper. Jony On Sunday, 14 September 2014 03:28:10 UTC+1, RJ Nowling wrote: > > Hi all, > > I'm new to Clojure and implementing a Markov Model as part of a larger > project. I'd like some advice on the API for a progress-state function. > > I see two possible options. In the first option, we always ask the user > to provide and keep track of the MSM state themselves: > > (progress-state markov-model previous-state) -> new-state > > In the second approach, we create a record that combines a model and a > current state: > > (defrecord MarkovProcess [model current-state]) > > (progress-state markov-process) -> updated-markov-process, new-state > > Which of these approaches is more idiomatic for Clojure? Are multiple > return types an accepted practice in Clojure? Is there a third, better way? > > Thanks in advance! > > RJ > -- 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.