Re: Creating a hashmap

2012-06-05 Thread Christian Guimaraes
Thanks for the tip, Timmy. This is a very interesting Vector feature.

-- christian

On Tue, Jun 5, 2012 at 7:13 PM, Tim Visher  wrote:

> On Tue, Jun 5, 2012 at 7:59 AM, Christian Guimaraes
>  wrote:
> > I hava a list (a b c) and want to create a hashmap using the elements
> from
> > this list.
> >
> > The keys will be a sequential number, and the values will be the values
> from
> > the previous list.
> >
> > 1. list:
> >   (a b c)
> >
> > 2. desired hashmap:
> >   (hash-map 1 "a" 2 "b" 3 "c")
> >
> > How can I achieve this in a idiomatic functional way?
>
> And now for something completely different:
>
>> ([1 2 3] 0)
>1
>> ([1 2 3] 1)
>2
>
> I refer, of course, to the strange property of vectors in that they
> are also functions of their index. So if you it's cool for you to have
> the list be a vector and the access to be vector first then 'key',
> then you need to write no code whatsoever.
>
> --
>
> Timmy V.
>
> http://twonegatives.com/
> http://five.sentenc.es/ -- Spend less time on mail.
>
> --
> 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 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

Re: Creating a hashmap

2012-06-05 Thread Tim Visher
On Tue, Jun 5, 2012 at 7:59 AM, Christian Guimaraes
 wrote:
> I hava a list (a b c) and want to create a hashmap using the elements from
> this list.
>
> The keys will be a sequential number, and the values will be the values from
> the previous list.
>
> 1. list:
>   (a b c)
>
> 2. desired hashmap:
>   (hash-map 1 "a" 2 "b" 3 "c")
>
> How can I achieve this in a idiomatic functional way?

And now for something completely different:

> ([1 2 3] 0)
1
> ([1 2 3] 1)
2

I refer, of course, to the strange property of vectors in that they
are also functions of their index. So if you it's cool for you to have
the list be a vector and the access to be vector first then 'key',
then you need to write no code whatsoever.

--

Timmy V.

http://twonegatives.com/
http://five.sentenc.es/ -- Spend less time on mail.

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


Re: Creating a hashmap

2012-06-05 Thread Meikel Brandmeyer (kotarak)
And a completely different approach:

(into {} (map-indexed #(vector (inc %1) %2) ["a" "b" "c"]))

Kind regards
Meikel

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

Re: Creating a hashmap

2012-06-05 Thread Jay Fields
If I needed the range to be infinite I'd probably use: (zipmap (iterate inc
1) '(a b c))

On Tue, Jun 5, 2012 at 8:13 AM, Baishampayan Ghose wrote:

> Or: (zipmap (drop 1 (range)) '(a b c))
>
> :-)
>
> Regards,
> BG
>
> On Tue, Jun 5, 2012 at 5:33 PM, Ambrose Bonnaire-Sergeant
>  wrote:
> > Or: (zipmap (map inc (range)) '(a b c))
> >
> > Thanks,
> > Ambrose
> >
> >
> > On Tue, Jun 5, 2012 at 8:02 PM, Jay Fields  wrote:
> >>
> >> (zipmap (range 1 4) ["a" "b" "c"])
> >>
> >>
> >> On Tue, Jun 5, 2012 at 7:59 AM, Christian Guimaraes
> >>  wrote:
> >>>
> >>> Hello all,
> >>>
> >>> I'm studying a little bit of Clojure and facing a doubt here.
> >>>
> >>> I hava a list (a b c) and want to create a hashmap using the elements
> >>> from this list.
> >>>
> >>> The keys will be a sequential number, and the values will be the values
> >>> from the previous list.
> >>>
> >>> 1. list:
> >>>   (a b c)
> >>>
> >>> 2. desired hashmap:
> >>>   (hash-map 1 "a" 2 "b" 3 "c")
> >>>
> >>> How can I achieve this in a idiomatic functional way?
> >>>
> >>> Cheers. And thank you for your attention.
> >>>
> >>> -- christian
> >>>
> >>> --
> >>> 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 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 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
>
>
>
> --
> Baishampayan Ghose
> b.ghose at gmail.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 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

Re: Creating a hashmap

2012-06-05 Thread Baishampayan Ghose
Or: (zipmap (drop 1 (range)) '(a b c))

:-)

Regards,
BG

On Tue, Jun 5, 2012 at 5:33 PM, Ambrose Bonnaire-Sergeant
 wrote:
> Or: (zipmap (map inc (range)) '(a b c))
>
> Thanks,
> Ambrose
>
>
> On Tue, Jun 5, 2012 at 8:02 PM, Jay Fields  wrote:
>>
>> (zipmap (range 1 4) ["a" "b" "c"])
>>
>>
>> On Tue, Jun 5, 2012 at 7:59 AM, Christian Guimaraes
>>  wrote:
>>>
>>> Hello all,
>>>
>>> I'm studying a little bit of Clojure and facing a doubt here.
>>>
>>> I hava a list (a b c) and want to create a hashmap using the elements
>>> from this list.
>>>
>>> The keys will be a sequential number, and the values will be the values
>>> from the previous list.
>>>
>>> 1. list:
>>>   (a b c)
>>>
>>> 2. desired hashmap:
>>>   (hash-map 1 "a" 2 "b" 3 "c")
>>>
>>> How can I achieve this in a idiomatic functional way?
>>>
>>> Cheers. And thank you for your attention.
>>>
>>> -- christian
>>>
>>> --
>>> 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 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 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



-- 
Baishampayan Ghose
b.ghose at gmail.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


Re: Creating a hashmap

2012-06-05 Thread Christian Guimaraes
Awesome...

I'm studying lists manipulation. Solidifying this concept. The basic in
Clojure, in my point of view.

Thanks again.

On Tue, Jun 5, 2012 at 1:03 PM, Ambrose Bonnaire-Sergeant <
abonnaireserge...@gmail.com> wrote:

> Or: (zipmap (map inc (range)) '(a b c))
>
> Thanks,
> Ambrose
>
>
> On Tue, Jun 5, 2012 at 8:02 PM, Jay Fields  wrote:
>
>> (zipmap (range 1 4) ["a" "b" "c"])
>>
>>
>> On Tue, Jun 5, 2012 at 7:59 AM, Christian Guimaraes <
>> cguimaraes...@gmail.com> wrote:
>>
>>> Hello all,
>>>
>>> I'm studying a little bit of Clojure and facing a doubt here.
>>>
>>> I hava a list (a b c) and want to create a hashmap using the elements
>>> from this list.
>>>
>>> The keys will be a sequential number, and the values will be the values
>>> from the previous list.
>>>
>>> 1. list:
>>>   (a b c)
>>>
>>> 2. desired hashmap:
>>>   (hash-map 1 "a" 2 "b" 3 "c")
>>>
>>> How can I achieve this in a idiomatic functional way?
>>>
>>> Cheers. And thank you for your attention.
>>>
>>> -- christian
>>>
>>> --
>>> 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 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 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 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

Re: Creating a hashmap

2012-06-05 Thread Ambrose Bonnaire-Sergeant
Or: (zipmap (map inc (range)) '(a b c))

Thanks,
Ambrose

On Tue, Jun 5, 2012 at 8:02 PM, Jay Fields  wrote:

> (zipmap (range 1 4) ["a" "b" "c"])
>
>
> On Tue, Jun 5, 2012 at 7:59 AM, Christian Guimaraes <
> cguimaraes...@gmail.com> wrote:
>
>> Hello all,
>>
>> I'm studying a little bit of Clojure and facing a doubt here.
>>
>> I hava a list (a b c) and want to create a hashmap using the elements
>> from this list.
>>
>> The keys will be a sequential number, and the values will be the values
>> from the previous list.
>>
>> 1. list:
>>   (a b c)
>>
>> 2. desired hashmap:
>>   (hash-map 1 "a" 2 "b" 3 "c")
>>
>> How can I achieve this in a idiomatic functional way?
>>
>> Cheers. And thank you for your attention.
>>
>> -- christian
>>
>> --
>> 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 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 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

Re: Creating a hashmap

2012-06-05 Thread Jay Fields
Also, if you're looking to learn this kind of stuff, 4clojure.com is an
excellent resource.

On Tue, Jun 5, 2012 at 8:02 AM, Jay Fields  wrote:

> (zipmap (range 1 4) ["a" "b" "c"])
>
>
> On Tue, Jun 5, 2012 at 7:59 AM, Christian Guimaraes <
> cguimaraes...@gmail.com> wrote:
>
>> Hello all,
>>
>> I'm studying a little bit of Clojure and facing a doubt here.
>>
>> I hava a list (a b c) and want to create a hashmap using the elements
>> from this list.
>>
>> The keys will be a sequential number, and the values will be the values
>> from the previous list.
>>
>> 1. list:
>>   (a b c)
>>
>> 2. desired hashmap:
>>   (hash-map 1 "a" 2 "b" 3 "c")
>>
>> How can I achieve this in a idiomatic functional way?
>>
>> Cheers. And thank you for your attention.
>>
>> -- christian
>>
>> --
>> 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 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

Re: Creating a hashmap

2012-06-05 Thread Jay Fields
(zipmap (range 1 4) ["a" "b" "c"])

On Tue, Jun 5, 2012 at 7:59 AM, Christian Guimaraes  wrote:

> Hello all,
>
> I'm studying a little bit of Clojure and facing a doubt here.
>
> I hava a list (a b c) and want to create a hashmap using the elements from
> this list.
>
> The keys will be a sequential number, and the values will be the values
> from the previous list.
>
> 1. list:
>   (a b c)
>
> 2. desired hashmap:
>   (hash-map 1 "a" 2 "b" 3 "c")
>
> How can I achieve this in a idiomatic functional way?
>
> Cheers. And thank you for your attention.
>
> -- christian
>
> --
> 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 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

Creating a hashmap

2012-06-05 Thread Christian Guimaraes
Hello all,

I'm studying a little bit of Clojure and facing a doubt here.

I hava a list (a b c) and want to create a hashmap using the elements from
this list.

The keys will be a sequential number, and the values will be the values
from the previous list.

1. list:
  (a b c)

2. desired hashmap:
  (hash-map 1 "a" 2 "b" 3 "c")

How can I achieve this in a idiomatic functional way?

Cheers. And thank you for your attention.

-- christian

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