Array destructuring appears to provide what you want with respect to nils (note the extra set of square braces within the argument list):
(defn make-map [[fullname lastname firstname middlename]] {:fullname fullname :lastname lastname :firstname firstname :middlename middlename}) (make-map ["John Lou Doe" "Doe" "John" "Lou"]) ;=> {:fullname "John Lou Doe", :lastname "Doe", :firstname "John", :middlename "Lou"} (make-map ["John Lou Doe" "Doe" "John"]) ;=> {:fullname "John Lou Doe", :lastname "Doe", :firstname "John", :middlename nil} (make-map ["John Lou Doe" "Doe"]) ;=> {:fullname "John Lou Doe", :lastname "Doe", :firstname nil, :middlename nil} (make-map ["John Lou Doe"]) ;=> {:fullname "John Lou Doe", :lastname nil, :firstname nil, :middlename nil} (make-map []) ;=> {:fullname nil, :lastname nil, :firstname nil, :middlename nil} (make-map nil) ;=> {:fullname nil, :lastname nil, :firstname nil, :middlename nil} On Sunday, June 1, 2014 12:09:35 PM UTC-4, Glen Rubin wrote: > > I am doing some text processing using clojure and attempting to extract a > person's name by regex and then assign it to a map. The result I get takes > one of several forms: > > nil (if i can't find the name) > > [fullname] > > [fullname lastname] > > [fullname lastname firstname] > > [fullname lastname firstname middlename] > > now, basically want to assign these entries to a map like so {:fullname > "some name", :lastname "some name", etc...} > > if there is no entry than I would like to assign it as nil, e.g. > {:fullname nil, lastname nil, etc...} > > I want to code this in the most proper way. I am thinking I need to > define a function that works differently based on how long the vector is? > How do I turn the contents of the vector into function arguments? > > Thanks! > > -- 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.