I would use 3 records: (defrecord DownNode [] SomeInterfaceApplicableToDownState (wake-up [_] (->WaitingNode)) ... InterfaceApplicableToAllNodes ...)
(defrecord WaitingNode [] SomeInterfaceApplicableToWaitingState (shutdown [_] (->DownNode)) (execute [_ job-id] (->RunningNode job-id)) ... InterfaceApplicableToAllNodes ...) (defrecord RunningNode [job-id] SomeInterfaceApplicableToRunningState ... InterfaceApplicableToAllNodes ...) After all, you won't be bashing the state of node in place, you will be constructing a new node at each modification. (unless you define the attrs mutable) On Tue, Mar 25, 2014 at 5:20 PM, László Török <ltoro...@gmail.com> wrote: > AFAIK the only thing that records do not support compared to StructMaps is > namespaced keyword lookup, i.e. (:some-ns/a-key a-record). > > If you do not need this, you should consider using records. > > Las > > On Tue, Mar 25, 2014 at 4:52 PM, Moritz Ulrich <mor...@tarn-vedra.de>wrote: > >> The data type created by defstruct isn't anything more than a map >> which can store the specified fields a bit more efficient than >> 'normal' maps. You can just `assoc' any other key-value pairs as in >> any other map. >> >> Also, have a look at records - I think StructMaps have been deprecated >> (or at least aren't recommended anymore) for some time now. A record >> (`defrecord') will do pretty much the same, just nicer ;-) >> >> On Tue, Mar 25, 2014 at 1:51 AM, <cmhowa...@alaska.edu> wrote: >> > Hi. I'm very new to Clojure, but I've read most of the functional >> > programming tutorial <http://java.ociweb.com/mark/clojure/article.html >> >. >> > >> > Suppose I have a data structure called "node" that can be in one of a >> number >> > of different states -- namely, "down", "waiting", and "running". Suppose >> > that in the "running" state, the node has a "job-id" number associated >> with >> > it, but such a number is not applicable in the other two states. Should >> I >> > add an extra field, and only check that field in the "running" state, >> like >> > so... >> > >> > (defstruct node :state :job-id) >> > >> > Or is there some better, or more "clojure-ish", way to approach this? >> > >> > If I was doing this in Haskell, I think that I would perhaps make some >> kind >> > of algebraic "NodeState" data type, and have the JobId only attached to >> the >> > Running constructor. >> > >> > -- >> > 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. >> >> -- >> 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. > > > -- > 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. > -- Kind Regards, Atamert Ölçgen -+- --+ +++ www.muhuk.com -- 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.