Erlang/OTP Forums

Author Message

<  Erlang patches mailing list  ~  lists:shuffle

Guest
Posted: Wed Mar 31, 2010 8:00 am Reply with quote
Guest
Hello,

Since I've been using Erlang, I've needed a function shuffle lists alot. Now
I was wondering if there could be a C implementation of this method in maybe
the lists module. Using this in raw erlang is much slower, and so I was
going to use the erl_nif interface along with some other lists functions to
make this faster. I want to know what you guys would think about
implementing this into the lists module.

William van Doorn


Post received from mailinglist
Guest
Posted: Wed Mar 31, 2010 8:00 am Reply with quote
Guest
Hello,

Since I've been using Erlang, I've needed a function shuffle lists alot. Now
I was wondering if there could be a C implementation of this method in maybe
the lists module. Using this in raw erlang is much slower, and so I was
going to use the erl_nif interface along with some other lists functions to
make this faster. I want to know what you guys would think about
implementing this into the lists module.

William van Doorn


Post received from mailinglist
Guest
Posted: Wed Mar 31, 2010 8:24 am Reply with quote
Guest
On Wed, Mar 31, 2010 at 10:00 AM, William v Doorn
<williamvdoorn@gmail.com> wrote:

> Since I've been using Erlang, I've needed a function shuffle lists alot. Now
> I was wondering if there could be a C implementation of this method in maybe
> the lists module. Using this in raw erlang is much slower, and so I was
> going to use the erl_nif interface along with some other lists functions to
> make this faster. I want to know what you guys would think about
> implementing this into the lists module.

We are generally wary about including new functions into the lists modules.
Only functions that would be useful for many users will be considered for
inclusion.

Another thing is that we don't want the lists module to start loading NIFs
(we will probably never have any NIFs in the kernel and stdlib applications).
If a function deserves to be in the lists module and if it should be
implemented in C, we will implement it as an ordinary BIF.

What exactly does your shuffle function do?

--
Björn Gustavsson, Erlang/OTP, Ericsson AB

________________________________________________________________
erlang-patches (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-patches-unsubscribe@erlang.org

Post received from mailinglist
Guest
Posted: Wed Mar 31, 2010 8:24 am Reply with quote
Guest
On Wed, Mar 31, 2010 at 10:00 AM, William v Doorn
<williamvdoorn@gmail.com> wrote:

> Since I've been using Erlang, I've needed a function shuffle lists alot. Now
> I was wondering if there could be a C implementation of this method in maybe
> the lists module. Using this in raw erlang is much slower, and so I was
> going to use the erl_nif interface along with some other lists functions to
> make this faster. I want to know what you guys would think about
> implementing this into the lists module.

We are generally wary about including new functions into the lists modules.
Only functions that would be useful for many users will be considered for
inclusion.

Another thing is that we don't want the lists module to start loading NIFs
(we will probably never have any NIFs in the kernel and stdlib applications).
If a function deserves to be in the lists module and if it should be
implemented in C, we will implement it as an ordinary BIF.

What exactly does your shuffle function do?

--
Björn Gustavsson, Erlang/OTP, Ericsson AB

________________________________________________________________
erlang-patches (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-patches-unsubscribe@erlang.org

Post received from mailinglist
Guest
Posted: Wed Mar 31, 2010 2:44 pm Reply with quote
Guest
(Please keep the discussion on the mailing list. I have
added back a CC to the list.)

2010/3/31 William v Doorn <williamvdoorn@gmail.com>:
> Hello,
>
> It's been implemented in the "standard" libaries of like every popular
> langauge. It basically shuffles the list. Here are two examples of
> implemenations:
>
> - Python: http://docs.python.org/library/random.html (Scroll down a bit)
> - Java:
> http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#shuffle(java.util.List)
>

I think that we might consider adding a shuffle() function to the
'random' module.

Could you show us your Erlang implementation shuffle() function that you
considered too slow. Perhaps it can be optimized to be fast enough. We
will need a reference implementation anyway, because we will not add
any new BIFs before benchmarking them to see whether the performance
improvement is significant enough.

--
Björn Gustavsson, Erlang/OTP, Ericsson AB

________________________________________________________________
erlang-patches (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-patches-unsubscribe@erlang.org

Post received from mailinglist
Guest
Posted: Wed Mar 31, 2010 2:44 pm Reply with quote
Guest
(Please keep the discussion on the mailing list. I have
added back a CC to the list.)

2010/3/31 William v Doorn <williamvdoorn@gmail.com>:
> Hello,
>
> It's been implemented in the "standard" libaries of like every popular
> langauge. It basically shuffles the list. Here are two examples of
> implemenations:
>
> - Python: http://docs.python.org/library/random.html (Scroll down a bit)
> - Java:
> http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#shuffle(java.util.List)
>

I think that we might consider adding a shuffle() function to the
'random' module.

Could you show us your Erlang implementation shuffle() function that you
considered too slow. Perhaps it can be optimized to be fast enough. We
will need a reference implementation anyway, because we will not add
any new BIFs before benchmarking them to see whether the performance
improvement is significant enough.

--
Björn Gustavsson, Erlang/OTP, Ericsson AB

________________________________________________________________
erlang-patches (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-patches-unsubscribe@erlang.org

Post received from mailinglist
Guest
Posted: Wed Mar 31, 2010 2:58 pm Reply with quote
Guest
2010/3/31 Björn Gustavsson <bgustavsson@gmail.com>:
> (Please keep the discussion on the mailing list. I have
> added back a CC to the list.)
>
> 2010/3/31 William v Doorn <williamvdoorn@gmail.com>:
>> Hello,
>>
>> It's been implemented in the "standard" libaries of like every popular
>> langauge. It basically shuffles the list. Here are two examples of
>> implemenations:
>>
>> - Python: http://docs.python.org/library/random.html (Scroll down a bit)
>> - Java:
>> http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#shuffle(java.util.List)
>>
>
> I think that we might consider adding a shuffle() function to the
> 'random' module.
>
> Could you show us your Erlang implementation shuffle() function that you
> considered too slow. Perhaps it can be optimized to be fast enough. We
> will need a reference implementation anyway, because we will not add
> any new BIFs before benchmarking them to see whether the performance
> improvement is significant enough.

It would be nice if the shuffle function provided a function and state
parameter for entropy so that you could decide whether to use
something deterministic (e.g. the functional API to random) or a
different source (e.g. the crypto module).

A shuffle function is something we'd find useful, but we've gotten by
without actually implementing a full and correct shuffle
implementation.

-bob

________________________________________________________________
erlang-patches (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-patches-unsubscribe@erlang.org

Post received from mailinglist
Guest
Posted: Wed Mar 31, 2010 2:58 pm Reply with quote
Guest
2010/3/31 Björn Gustavsson <bgustavsson@gmail.com>:
> (Please keep the discussion on the mailing list. I have
> added back a CC to the list.)
>
> 2010/3/31 William v Doorn <williamvdoorn@gmail.com>:
>> Hello,
>>
>> It's been implemented in the "standard" libaries of like every popular
>> langauge. It basically shuffles the list. Here are two examples of
>> implemenations:
>>
>> - Python: http://docs.python.org/library/random.html (Scroll down a bit)
>> - Java:
>> http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#shuffle(java.util.List)
>>
>
> I think that we might consider adding a shuffle() function to the
> 'random' module.
>
> Could you show us your Erlang implementation shuffle() function that you
> considered too slow. Perhaps it can be optimized to be fast enough. We
> will need a reference implementation anyway, because we will not add
> any new BIFs before benchmarking them to see whether the performance
> improvement is significant enough.

It would be nice if the shuffle function provided a function and state
parameter for entropy so that you could decide whether to use
something deterministic (e.g. the functional API to random) or a
different source (e.g. the crypto module).

A shuffle function is something we'd find useful, but we've gotten by
without actually implementing a full and correct shuffle
implementation.

-bob

________________________________________________________________
erlang-patches (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-patches-unsubscribe@erlang.org

Post received from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum