Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #24313
| From | Arved Sandstrom <asandstrom2@eastlink.ca> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Java 8 Streams and Eratosthenes |
| 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> |
| Message-ID | <IpNrt.2$He1.1@newsfe05.iad> (permalink) |
| Organization | Public Usenet Newsgroup Access |
| Date | 2013-06-05 17:43 -0300 |
On 06/05/2013 04:44 AM, Sebastian wrote:
> Am 05.06.2013 09:03, schrieb Sebastian:
>> Am 05.06.2013 00:35, schrieb Arved Sandstrom:
>>> On 06/04/2013 06:54 PM, Sebastian wrote:
>>>> Hello there,
>>>>
>>>> I'd like to start an open discussion on issues involving the Streams
>>>> API. As an exercise, I have looked at generating the first n primes,
>>>> for some given n, using the sieve of Eratosthenes. It seemed a
>>>> plausible enough proposition, seeing that the sieve involves repeatedly
>>>> filtering a sequence of integers.
>>>>
>> [snip]
>>>>
>>>> Perhaps the lesson is that some things are best not done using
>>>> streams.
>> [snip]
>>>>
>>>> What are your opinions?
>>>>
>>>> Best,
>>>> Sebastian
>>> [ SNIP ]
>>>
>>> Some things are best not done using Java. Given interop, I'd use Closure
>>> or Scala for this type of stuff, if the main program is still Java.
>>>
>>> AHS
>>
>> That's a bit of a dodge, isn't it? Scala may be a nice language, but
>> that doesn't help with investigating Java's strength and weaknesses.
>>
>> -- Sebastian
>
> Or perhaps it does. There are many Scala implementations of this
> algorithm on the internet, cf. this one
>
> def primes : Stream[Int] = {
>
> var is = Stream from 2
>
> def sieve(numbers: Stream[Int]): Stream[Int] = {
> Stream.cons(
> numbers.head,
> sieve(for (x <- numbers.tail if x % numbers.head > 0) yield x))
> }
>
> sieve(is)
> }
>
> from
> http://louisbotterill.blogspot.de/2009/07/scala-lazy-evaluation-and-sieve-of.html
>
>
> What the implementations all seem to have in common is the ability to
> access the head of the stream and still lazily operate on the rest. It
> is an ability that Java streams lack. So perhaps the way to go is to
> create a sort of LazyLinkedList in Java (if there isn't one.)
>
> -- Sebastian
>
Me I wouldn't re-invent the wheel in this case. Implementing this type
of laziness is not that straightforward.
And why not use interop between JVM languages? This way you leverage the
strengths. I usually have Java as the main language, but for some
functionality in some apps I use Scala. Maintainability goes up, for
starters, as does reliability and speed of development.
It's all ultimately JVM bytecode.
AHS
--
When a true genius appears, you can know him by this sign:
that all the dunces are in a confederacy against him.
-- Jonathan Swift
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