Re: text processing function

2014-06-01 Thread Mike Fikes
Hey Glen, it appears that zipmap most directly corresponds to your initial 
question.

The only complicating aspect is your desire for nils, which (concat result 
(repeat nil)) addresses. 

  (zipmap [:fullname :lastname :firstname :middlename] (concat result 
(repeat nil)))

If it weren't for the need for nils,

  (zipmap [:fullname :lastname :firstname :middlename] result)

is simple and noise-free.  Note that the nils are unnecessary if later 
using map destructuring:

   (defn use-names [{:keys [fullname lastname firstname middlename]}] 
(println fullname lastname firstname middlename))

For example, nils are generated at call time for you by the map 
destructuring:

  (use-names (zipmap [:fullname :lastname :firstname :middlename] ["John 
Lou Doe" "Doe" "John"]))

  ;=> John Lou Doe Doe John nil



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


Re: text processing function

2014-06-01 Thread Mike Fikes
Just golfing for fun:

(apply hash-map (interleave [:fullname :lastname :firstname :middlename] 
(concat ["John Lou Doe" "Doe" "John"] (repeat nil


;=> {:firstname "John", :lastname "Doe", :middlename nil, :fullname "John 
Lou Doe"}


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


Re: text processing function

2014-06-01 Thread Glen Rubin
These are both very good and usable answers.  Thank you both!

On Sunday, June 1, 2014 9:36:58 AM UTC-7, James Reeves wrote:
>
> What about:
>
> {:fullname (get result 0), :lastname (get result 1), :firstname (get 
> result 2), :middlename (get result 3)}
>
> If the "get" function can't find a result, it returns nil.
>
> - James
>
>
> On 1 June 2014 17:09, 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 clo...@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+u...@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+u...@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.


Re: text processing function

2014-06-01 Thread James Reeves
What about:

{:fullname (get result 0), :lastname (get result 1), :firstname (get result
2), :middlename (get result 3)}

If the "get" function can't find a result, it returns nil.

- James


On 1 June 2014 17:09, 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.
>

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


Re: text processing function

2014-06-01 Thread Mike Fikes
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.


text processing function

2014-06-01 Thread Glen Rubin
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.