Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #24430
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail |
|---|---|
| From | Sebastian <news@seyweiler.dyndns.org> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) |
| Date | Sun, 16 Jun 2013 22:52:24 +0200 |
| Organization | albasani.net |
| Lines | 61 |
| Message-ID | <kpl8hs$71e$1@news.albasani.net> (permalink) |
| References | <kolnme$g3e$1@news.albasani.net> <ZYtrt.80089$cD1.53480@newsfe29.iad> <komnrp$3sh$1@news.albasani.net> <komq8g$8hc$1@news.albasani.net> <IpNrt.2$He1.1@newsfe05.iad> <kp331c$n68$1@news.albasani.net> <LY9tt.66779$vh.52483@newsfe20.iad> <kp5382$hqg$1@news.albasani.net> <kp5c15$u7r$1@dont-email.me> <kp84nr$8h7$1@news.albasani.net> <kp9q20$7c5$1@news.albasani.net> <kpioud$2ct$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Trace | news.albasani.net zVSGhyWypAd6drVzlaEaBG1jZJpuUBLLzLNuqJu9h/82DuzmTffU+Xni3j97dthxv/jjk1KXkNHKyIqE0wqIiQ== |
| NNTP-Posting-Date | Sun, 16 Jun 2013 20:52:12 +0000 (UTC) |
| Injection-Info | news.albasani.net; logging-data="WDICR7Xh57dnTo/CpmuPFCNEThBkcxFIKevef1XpLP148+czKIxV7h4tNrUpA2Ewk4I2zEobukR36L2poPvxOmHp0o/0YbdsbviV6F3JFy+qD30oEryTdz21J5w9KXQC"; mail-complaints-to="abuse@albasani.net" |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 |
| In-Reply-To | <kpioud$2ct$1@dont-email.me> |
| Cancel-Lock | sha1:5kkA5c7TLPnBmjUhC99lSb4BgNI= |
| Xref | csiph.com comp.lang.java.programmer:24430 |
Show key headers only | View raw
Am 16.06.2013 00:18, schrieb markspace:
> On 6/12/2013 5:37 AM, Sebastian wrote:
>> Am 11.06.2013 23:27, schrieb Sebastian:
>> [snip]
>>>
>>> I have thought again, and will put something together on a blog. May
>>> take a day or two, I'll be back to post a link. It will still be hard
>>> to follow, though. Meanwhile, a good place to get started with the topic
>>> would be Maurice Naftalin's Lambda FAQ at http://www.lambdafaq.org/
>>>
>>> -- Sebastian
>>
>> I have written two blog entries about higher-order functions with Java 8
>> lambda expressions. They can be found at
>>
>> http://sebastian-millies.blogspot.de/
>
> So I had a chance to look at this a bit. Lambda are kind of cool. You
> can generate lists of number easily:
>
> static void test1() {
> Stream.iterate( 0, x -> x + 1 )
> ;
> }
>
yes, I think its a good thing this is being added to Java. A real advance.
> This actually runs, even though the list is infinite. Many streams are
> lazy, and don't evaluate unless asked for more. I guess the stream above
> initializes its values, but then never generates any numbers since it's
> never asked for any.
yes, that's how it works. By the way, streams are not only lazy, but
many tasks that work on streams can be parallelized by just calling the
parallel() method on the stream. That's explicit but unobtrusive - all
the concurrent stuff happens under the hood (based on the
fork-join-framework of Java 7). I haven't yet looked at this in detail,
though.
[snip]
> So to make this print primes, we have to filter a little differently. I
> really didn't understand the code in your first post, so I might be
> missing some points here. But I followed the example that you linked to
> earlier:
>
> Cf. this paper by Melissa E. O’Neil:
> http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
>
> And I gave that a go. The trick is to define your own predicate. No,
> it's not really a lambda at that point, but it does work, and with less
> code than either your first example or your blog. (Although barely less.)
[snip]
that's good to see. Thanks for sharing the code. It's nice having a real
sieve of Eratosthenes now. (But I still like the simple formulation of
the naive algorithm, just for its looks - although objectively it
performs worse.)
I also like your step-by-step exposition.
Best Regards,
Sebastian
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Java 8 Streams and Eratosthenes Sebastian <news@seyweiler.dyndns.org> - 2013-06-04 23:54 +0200
Re: Java 8 Streams and Eratosthenes Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-04 19:35 -0300
Re: Java 8 Streams and Eratosthenes Sebastian <news@seyweiler.dyndns.org> - 2013-06-05 09:03 +0200
Re: Java 8 Streams and Eratosthenes Sebastian <news@seyweiler.dyndns.org> - 2013-06-05 09:44 +0200
Re: Java 8 Streams and Eratosthenes Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-05 17:43 -0300
Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-10 01:27 +0200
Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-09 22:28 -0300
Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-10 19:43 +0200
Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) markspace <markspace@nospam.nospam> - 2013-06-10 13:18 -0700
Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-11 23:27 +0200
Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-12 10:32 +0200
Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-12 14:37 +0200
Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) markspace <markspace@nospam.nospam> - 2013-06-12 12:05 -0700
Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-12 22:53 +0200
Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) markspace <markspace@nospam.nospam> - 2013-06-15 15:18 -0700
Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-16 22:52 +0200
Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-16 21:56 -0300
Re: Lazy primes with Java 8 (was Re: Java 8 Streams and Eratosthenes) Sebastian <news@seyweiler.dyndns.org> - 2013-06-18 23:18 +0200
Re: Java 8 Streams and Eratosthenes markspace <markspace@nospam.nospam> - 2013-06-04 17:24 -0700
Re: Java 8 Streams and Eratosthenes Sebastian <news@seyweiler.dyndns.org> - 2013-06-05 09:09 +0200
Re: Java 8 Streams and Eratosthenes markspace <markspace@nospam.nospam> - 2013-06-05 09:45 -0700
Re: Java 8 Streams and Eratosthenes Sebastian <news@seyweiler.dyndns.org> - 2013-06-05 21:32 +0200
Re: Java 8 Streams and Eratosthenes Sebastian <news@seyweiler.dyndns.org> - 2013-06-05 09:47 +0200
csiph-web