You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Bruno P. Kinoshita" <br...@yahoo.com.br> on 2012/01/23 01:15:47 UTC
[functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
Hi all,
In functor, there are two ranges available: IntegerRange and LongRange. Both use a closed open interval, i.e., the low limit is included in the range, while the high limit is not.
In Perl, we can create a range of numbers too, using the range operator (..). Something like 0..10. What produces a closed interval (both 0 and 10 are included). And in Perl, we can create a range of chars too. Like an alphabet, a..z. Again, a closed interval.
With the current implementation of Ranges in functor, if I want a closed interval from 0 to 10, I have to create the following code (limited by 0 and 11), that produces a closed/open interval.
IntegerRange range = newIntegerRange(0, 11);
Now, if I create a CharacterRange, the implementation would have to use a closed interval (otherwise z would never be included).
CharacterRange range = newCharacterRange('a', 'z');
IMHO, we could change the current implementation, before the first release, to use a closed interval. It means that it would always include the low and high limits. This way, both an IntegerRange and a CharacterRange, would have the same behavior, respecting the Liskov Principle of Substitution. What do you think? If that sounds reasonable, I could file an issue for the change of behavior in JIRA, and another JIRA with an CharacterRange plus tests, and an example for the web site.
Another thing, I have to use float intervals for fuzzy membership functions in a project. As I am already using functor there, I thought I could create a FloatRange and a DoubleRange for functor. What do you think? If this sounds good too, I will file an issue in JIRA for this too, with tests and examples for the web site.
I wrote a blog entry to organize my findings while I compared functor ranges with other API's and programming languages, maybe someone will find it interesting - http://www.kinoshita.eti.br/2012/01/22/ranges-in-apache-functor/
There are other points in Integer and Long ranges that I found confusing. Like, if you call isStopped() before, during the iteration or after you iterated over the elements, the result is always false. Not sure if this is the right behavior for it. Perhaps this method could be moved from Generator to a StoppableGenerator interface, that WhileGenerator, GenerateUntil and others would implement (maybe even the IntegerRange, or a StoppableIntegerRange. Try creating a IntegerRange from 0 to Integer.MAX_VALUE and print the values with a UnaryProcedure... that may take some time :)
Thank you in advance!
Bruno P. Kinoshita
http://kinoshita.eti.br
http://tupilabs.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
Posted by "Bruno P. Kinoshita" <br...@yahoo.com.br>.
Hi Matt,
I have just created an issue for the work on enhancements on the Generator API [1].
> I will try to take a look at this this week.
Thanks Matt, in the meantime I will read other parts of the code base and will work on the other existing issues to see if I can provide patches for them too.
>However, I would urge you not to look at their actual code,
>rather looking at APIs only. This way you can be sure that any
>patches you may provide [functor] are free and clear from an IP
>perspective.
Thanks for the heads up! I will keep that in mind when creating the patches :-)
Cheers,
[1] https://issues.apache.org/jira/browse/FUNCTOR-14
Bruno P. Kinoshita
http://kinoshita.eti.br
http://tupilabs.com
>________________________________
> From: Matt Benson <gu...@gmail.com>
>To: Commons Developers List <de...@commons.apache.org>; Bruno P. Kinoshita <br...@yahoo.com.br>
>Sent: Tuesday, 14 February 2012 7:33 PM
>Subject: Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
>
>On Tue, Feb 14, 2012 at 3:00 PM, Bruno P. Kinoshita
><br...@yahoo.com.br> wrote:
>> Hi all,
>>
>> Looks like the initial code [1] for the Generators API in Apache Commons Functor was created based on the Python generators [2].
>>
>> After playing for a while with Python generators, I realized many examples have a 'generator', a 'range' and a 'yield' statement. Then I looked for existing Java API's with generators, ranges and/or *yields* to have more ideas for [functor]'s Generator API.
>>
>> I found one [3] that requires some bytecode manipulation, and another one [4] that uses a threading mechanism to yield objects.
>>
>> I tried both of them [5] and the latter, java-yielder, seems to provide a useful Yield API, as well as Generator and Ranges. There are few modifications that I would like to see in its Range, like the possibility to make the boundary values inclusive or exclusive (like in Google Guava). As well as include a StoppableGenerator interface to the Generator API, so we could maintain the existing implementations in [functor] of Generators.
>>
>>
>> If there are no objections, I will fill an issue in JIRA for enhancements on the Generator API in [functor], where we can further discuss on this issue as well as attach patches :-) I believe we could have similar separation in [functor], Generators, Ranges, and maybe, Yields. However, it would be good if someone else could have a look on java-yielder and other existing Yields implementations for Java.
>>
>>
>> And if everybody thinks it is appropriate and the API is good enough, maybe we could ping the author of java-yielder and see if he would be willing to donate the code to ASF? It is licensed under the BSD-License [6], not sure if it is compatible with the Apache License.
>>
>
>Bruno,
> I will try to take a look at this this week. If we like its API and
>java-yielder's author/s are willing to grant us a license, that's
>great. However, I would urge you not to look at their actual code,
>rather looking at APIs only. This way you can be sure that any
>patches you may provide [functor] are free and clear from an IP
>perspective.
>
>br,
>Matt
>
>>
>> Looking forward to hearing your thoughts on this!
>>
>>
>> [1] http://markmail.org/message/rtnn2xpudw3ygtvr#query:+page:1+mid:ynfmtd4shswtuvz7+state:results
>>
>> [2]http://www.dabeaz.com/generators/
>>
>> [3] http://code.google.com/p/infomancers-collections/
>>
>> [4] http://code.google.com/p/java-yield/
>> [5] https://github.com/kinow/yields-tests/tree/master/src/main/java/sample/yield
>> [6] http://www.opensource.org/licenses/bsd-license.php
>>
>>
>> Cheers,
>>
>> Bruno P. Kinoshita
>> http://kinoshita.eti.br
>> http://tupilabs.com
>>
>>
>>>________________________________
>>> From: Adrian Crum <ad...@sandglass-software.com>
>>>To: Commons Developers List <de...@commons.apache.org>
>>>Sent: Tuesday, 24 January 2012 7:21 PM
>>>Subject: Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
>>>
>>>After looking at the Lang 3 Range API, I realized an Iterator factory
>>>should be kept external to the Range class:
>>>
>>>Range<Date> dateRange = Range.between(thisMonth, nextMonth);
>>>Iterator<Date> dayIterator = RangeIteratorFactory.getInstance(dateRange,
>>>Calendar.DATE);
>>>
>>>Range<Integer> intRange = Range.between(firstInt, lastInt);
>>>Iterator<Integer> intSeqIterator =
>>>RangeIteratorFactory.getInstance(intRange, 3);
>>>
>>>-Adrian
>>>
>>>On 1/24/2012 9:10 PM, Bruno P. Kinoshita wrote:
>>>>
>>>> Sounds great for me too :)
>>>>
>>>>
>>>> Cheers,
>>>>
>>>>
>>>> Bruno P. Kinoshita
>>>> http://kinoshita.eti.br
>>>> http://tupilabs.com
>>>>
>>>>
>>>> ----- Mensagem original -----
>>>>> De: Adrian Crum<ad...@sandglass-software.com>
>>>>> Para: Commons Developers List<de...@commons.apache.org>
>>>>> Cc:
>>>>> Enviadas: Terça-feira, 24 de Janeiro de 2012 18:30
>>>>> Assunto: Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
>>>>>
>>>>> On 1/24/2012 8:15 PM, Matt Benson wrote:
>>>>>> Thanks for your interest, Adrian! Comments inline:
>>>>>>
>>>>>> On Tue, Jan 24, 2012 at 1:58 PM, Adrian Crum
>>>>>> <ad...@sandglass-software.com> wrote:
>>>>>>> On 1/24/2012 6:58 PM, Matt Benson wrote:
>>>>>>>> IMO the difference between [lang]'s and [functor]'s range
>>>>> concepts is that
>>>>>>>> those in [lang] are intended to be able to say whether a given
>>>>> value is in
>>>>>>>> the Range, but, with the exception of CharRange (this class is not
>>>>> even
>>>>>>>> public), they make no provision for iterating over members of the
>>>>> range. I
>>>>>>>> would therefore design a [functor]-targeted Range builder API to
>>>>> allow the
>>>>>>>> user to specify how next values are obtained. Range may not even be
>>>>> the best
>>>>>>>> word to describe the behavior we are trying to model here, so
>>>>> let's be open
>>>>>>>> to reinterpretation as we proceed.
>>>>>>> From my perspective, Range + Step = Sequence.
>>>>>> I'll buy that if noone else objects. :)
>>>>>>
>>>>>>> A Range iterator would be
>>>>>>> useful for implementing mathematical sets.
>>>>>> e.g. integer range a..b step 3 yields the sequence of integers n
>>>>>> greater than or equal to a and less than or equal to b where (n - a) %
>>>>>> 3 == 0 ? Is this useful?
>>>>>>
>>>>>> Matt
>>>>> It would be useful for a mathematician. Another possibility is a Range
>>>>> of Dates, with a step of one hour, or one day or...
>>>>>
>>>>> The Range class could accept an Iterator factory so various steps can be
>>>>> implemented in client code.
>>>>>
>>>>> -Adrian
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
Posted by Matt Benson <gu...@gmail.com>.
On Tue, Feb 14, 2012 at 3:00 PM, Bruno P. Kinoshita
<br...@yahoo.com.br> wrote:
> Hi all,
>
> Looks like the initial code [1] for the Generators API in Apache Commons Functor was created based on the Python generators [2].
>
> After playing for a while with Python generators, I realized many examples have a 'generator', a 'range' and a 'yield' statement. Then I looked for existing Java API's with generators, ranges and/or *yields* to have more ideas for [functor]'s Generator API.
>
> I found one [3] that requires some bytecode manipulation, and another one [4] that uses a threading mechanism to yield objects.
>
> I tried both of them [5] and the latter, java-yielder, seems to provide a useful Yield API, as well as Generator and Ranges. There are few modifications that I would like to see in its Range, like the possibility to make the boundary values inclusive or exclusive (like in Google Guava). As well as include a StoppableGenerator interface to the Generator API, so we could maintain the existing implementations in [functor] of Generators.
>
>
> If there are no objections, I will fill an issue in JIRA for enhancements on the Generator API in [functor], where we can further discuss on this issue as well as attach patches :-) I believe we could have similar separation in [functor], Generators, Ranges, and maybe, Yields. However, it would be good if someone else could have a look on java-yielder and other existing Yields implementations for Java.
>
>
> And if everybody thinks it is appropriate and the API is good enough, maybe we could ping the author of java-yielder and see if he would be willing to donate the code to ASF? It is licensed under the BSD-License [6], not sure if it is compatible with the Apache License.
>
Bruno,
I will try to take a look at this this week. If we like its API and
java-yielder's author/s are willing to grant us a license, that's
great. However, I would urge you not to look at their actual code,
rather looking at APIs only. This way you can be sure that any
patches you may provide [functor] are free and clear from an IP
perspective.
br,
Matt
>
> Looking forward to hearing your thoughts on this!
>
>
> [1] http://markmail.org/message/rtnn2xpudw3ygtvr#query:+page:1+mid:ynfmtd4shswtuvz7+state:results
>
> [2]http://www.dabeaz.com/generators/
>
> [3] http://code.google.com/p/infomancers-collections/
>
> [4] http://code.google.com/p/java-yield/
> [5] https://github.com/kinow/yields-tests/tree/master/src/main/java/sample/yield
> [6] http://www.opensource.org/licenses/bsd-license.php
>
>
> Cheers,
>
> Bruno P. Kinoshita
> http://kinoshita.eti.br
> http://tupilabs.com
>
>
>>________________________________
>> From: Adrian Crum <ad...@sandglass-software.com>
>>To: Commons Developers List <de...@commons.apache.org>
>>Sent: Tuesday, 24 January 2012 7:21 PM
>>Subject: Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
>>
>>After looking at the Lang 3 Range API, I realized an Iterator factory
>>should be kept external to the Range class:
>>
>>Range<Date> dateRange = Range.between(thisMonth, nextMonth);
>>Iterator<Date> dayIterator = RangeIteratorFactory.getInstance(dateRange,
>>Calendar.DATE);
>>
>>Range<Integer> intRange = Range.between(firstInt, lastInt);
>>Iterator<Integer> intSeqIterator =
>>RangeIteratorFactory.getInstance(intRange, 3);
>>
>>-Adrian
>>
>>On 1/24/2012 9:10 PM, Bruno P. Kinoshita wrote:
>>>
>>> Sounds great for me too :)
>>>
>>>
>>> Cheers,
>>>
>>>
>>> Bruno P. Kinoshita
>>> http://kinoshita.eti.br
>>> http://tupilabs.com
>>>
>>>
>>> ----- Mensagem original -----
>>>> De: Adrian Crum<ad...@sandglass-software.com>
>>>> Para: Commons Developers List<de...@commons.apache.org>
>>>> Cc:
>>>> Enviadas: Terça-feira, 24 de Janeiro de 2012 18:30
>>>> Assunto: Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
>>>>
>>>> On 1/24/2012 8:15 PM, Matt Benson wrote:
>>>>> Thanks for your interest, Adrian! Comments inline:
>>>>>
>>>>> On Tue, Jan 24, 2012 at 1:58 PM, Adrian Crum
>>>>> <ad...@sandglass-software.com> wrote:
>>>>>> On 1/24/2012 6:58 PM, Matt Benson wrote:
>>>>>>> IMO the difference between [lang]'s and [functor]'s range
>>>> concepts is that
>>>>>>> those in [lang] are intended to be able to say whether a given
>>>> value is in
>>>>>>> the Range, but, with the exception of CharRange (this class is not
>>>> even
>>>>>>> public), they make no provision for iterating over members of the
>>>> range. I
>>>>>>> would therefore design a [functor]-targeted Range builder API to
>>>> allow the
>>>>>>> user to specify how next values are obtained. Range may not even be
>>>> the best
>>>>>>> word to describe the behavior we are trying to model here, so
>>>> let's be open
>>>>>>> to reinterpretation as we proceed.
>>>>>> From my perspective, Range + Step = Sequence.
>>>>> I'll buy that if noone else objects. :)
>>>>>
>>>>>> A Range iterator would be
>>>>>> useful for implementing mathematical sets.
>>>>> e.g. integer range a..b step 3 yields the sequence of integers n
>>>>> greater than or equal to a and less than or equal to b where (n - a) %
>>>>> 3 == 0 ? Is this useful?
>>>>>
>>>>> Matt
>>>> It would be useful for a mathematician. Another possibility is a Range
>>>> of Dates, with a step of one hour, or one day or...
>>>>
>>>> The Range class could accept an Iterator factory so various steps can be
>>>> implemented in client code.
>>>>
>>>> -Adrian
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
Posted by "Bruno P. Kinoshita" <br...@yahoo.com.br>.
Hi all,
Looks like the initial code [1] for the Generators API in Apache Commons Functor was created based on the Python generators [2].
After playing for a while with Python generators, I realized many examples have a 'generator', a 'range' and a 'yield' statement. Then I looked for existing Java API's with generators, ranges and/or *yields* to have more ideas for [functor]'s Generator API.
I found one [3] that requires some bytecode manipulation, and another one [4] that uses a threading mechanism to yield objects.
I tried both of them [5] and the latter, java-yielder, seems to provide a useful Yield API, as well as Generator and Ranges. There are few modifications that I would like to see in its Range, like the possibility to make the boundary values inclusive or exclusive (like in Google Guava). As well as include a StoppableGenerator interface to the Generator API, so we could maintain the existing implementations in [functor] of Generators.
If there are no objections, I will fill an issue in JIRA for enhancements on the Generator API in [functor], where we can further discuss on this issue as well as attach patches :-) I believe we could have similar separation in [functor], Generators, Ranges, and maybe, Yields. However, it would be good if someone else could have a look on java-yielder and other existing Yields implementations for Java.
And if everybody thinks it is appropriate and the API is good enough, maybe we could ping the author of java-yielder and see if he would be willing to donate the code to ASF? It is licensed under the BSD-License [6], not sure if it is compatible with the Apache License.
Looking forward to hearing your thoughts on this!
[1] http://markmail.org/message/rtnn2xpudw3ygtvr#query:+page:1+mid:ynfmtd4shswtuvz7+state:results
[2]http://www.dabeaz.com/generators/
[3] http://code.google.com/p/infomancers-collections/
[4] http://code.google.com/p/java-yield/
[5] https://github.com/kinow/yields-tests/tree/master/src/main/java/sample/yield
[6] http://www.opensource.org/licenses/bsd-license.php
Cheers,
Bruno P. Kinoshita
http://kinoshita.eti.br
http://tupilabs.com
>________________________________
> From: Adrian Crum <ad...@sandglass-software.com>
>To: Commons Developers List <de...@commons.apache.org>
>Sent: Tuesday, 24 January 2012 7:21 PM
>Subject: Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
>
>After looking at the Lang 3 Range API, I realized an Iterator factory
>should be kept external to the Range class:
>
>Range<Date> dateRange = Range.between(thisMonth, nextMonth);
>Iterator<Date> dayIterator = RangeIteratorFactory.getInstance(dateRange,
>Calendar.DATE);
>
>Range<Integer> intRange = Range.between(firstInt, lastInt);
>Iterator<Integer> intSeqIterator =
>RangeIteratorFactory.getInstance(intRange, 3);
>
>-Adrian
>
>On 1/24/2012 9:10 PM, Bruno P. Kinoshita wrote:
>>
>> Sounds great for me too :)
>>
>>
>> Cheers,
>>
>>
>> Bruno P. Kinoshita
>> http://kinoshita.eti.br
>> http://tupilabs.com
>>
>>
>> ----- Mensagem original -----
>>> De: Adrian Crum<ad...@sandglass-software.com>
>>> Para: Commons Developers List<de...@commons.apache.org>
>>> Cc:
>>> Enviadas: Terça-feira, 24 de Janeiro de 2012 18:30
>>> Assunto: Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
>>>
>>> On 1/24/2012 8:15 PM, Matt Benson wrote:
>>>> Thanks for your interest, Adrian! Comments inline:
>>>>
>>>> On Tue, Jan 24, 2012 at 1:58 PM, Adrian Crum
>>>> <ad...@sandglass-software.com> wrote:
>>>>> On 1/24/2012 6:58 PM, Matt Benson wrote:
>>>>>> IMO the difference between [lang]'s and [functor]'s range
>>> concepts is that
>>>>>> those in [lang] are intended to be able to say whether a given
>>> value is in
>>>>>> the Range, but, with the exception of CharRange (this class is not
>>> even
>>>>>> public), they make no provision for iterating over members of the
>>> range. I
>>>>>> would therefore design a [functor]-targeted Range builder API to
>>> allow the
>>>>>> user to specify how next values are obtained. Range may not even be
>>> the best
>>>>>> word to describe the behavior we are trying to model here, so
>>> let's be open
>>>>>> to reinterpretation as we proceed.
>>>>> From my perspective, Range + Step = Sequence.
>>>> I'll buy that if noone else objects. :)
>>>>
>>>>> A Range iterator would be
>>>>> useful for implementing mathematical sets.
>>>> e.g. integer range a..b step 3 yields the sequence of integers n
>>>> greater than or equal to a and less than or equal to b where (n - a) %
>>>> 3 == 0 ? Is this useful?
>>>>
>>>> Matt
>>> It would be useful for a mathematician. Another possibility is a Range
>>> of Dates, with a step of one hour, or one day or...
>>>
>>> The Range class could accept an Iterator factory so various steps can be
>>> implemented in client code.
>>>
>>> -Adrian
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>For additional commands, e-mail: dev-help@commons.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed
intervals
Posted by Adrian Crum <ad...@sandglass-software.com>.
After looking at the Lang 3 Range API, I realized an Iterator factory
should be kept external to the Range class:
Range<Date> dateRange = Range.between(thisMonth, nextMonth);
Iterator<Date> dayIterator = RangeIteratorFactory.getInstance(dateRange,
Calendar.DATE);
Range<Integer> intRange = Range.between(firstInt, lastInt);
Iterator<Integer> intSeqIterator =
RangeIteratorFactory.getInstance(intRange, 3);
-Adrian
On 1/24/2012 9:10 PM, Bruno P. Kinoshita wrote:
>
> Sounds great for me too :)
>
>
> Cheers,
>
>
> Bruno P. Kinoshita
> http://kinoshita.eti.br
> http://tupilabs.com
>
>
> ----- Mensagem original -----
>> De: Adrian Crum<ad...@sandglass-software.com>
>> Para: Commons Developers List<de...@commons.apache.org>
>> Cc:
>> Enviadas: Terça-feira, 24 de Janeiro de 2012 18:30
>> Assunto: Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
>>
>> On 1/24/2012 8:15 PM, Matt Benson wrote:
>>> Thanks for your interest, Adrian! Comments inline:
>>>
>>> On Tue, Jan 24, 2012 at 1:58 PM, Adrian Crum
>>> <ad...@sandglass-software.com> wrote:
>>>> On 1/24/2012 6:58 PM, Matt Benson wrote:
>>>>> IMO the difference between [lang]'s and [functor]'s range
>> concepts is that
>>>>> those in [lang] are intended to be able to say whether a given
>> value is in
>>>>> the Range, but, with the exception of CharRange (this class is not
>> even
>>>>> public), they make no provision for iterating over members of the
>> range. I
>>>>> would therefore design a [functor]-targeted Range builder API to
>> allow the
>>>>> user to specify how next values are obtained. Range may not even be
>> the best
>>>>> word to describe the behavior we are trying to model here, so
>> let's be open
>>>>> to reinterpretation as we proceed.
>>>> From my perspective, Range + Step = Sequence.
>>> I'll buy that if noone else objects. :)
>>>
>>>> A Range iterator would be
>>>> useful for implementing mathematical sets.
>>> e.g. integer range a..b step 3 yields the sequence of integers n
>>> greater than or equal to a and less than or equal to b where (n - a) %
>>> 3 == 0 ? Is this useful?
>>>
>>> Matt
>> It would be useful for a mathematician. Another possibility is a Range
>> of Dates, with a step of one hour, or one day or...
>>
>> The Range class could accept an Iterator factory so various steps can be
>> implemented in client code.
>>
>> -Adrian
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
Posted by "Bruno P. Kinoshita" <br...@yahoo.com.br>.
Sounds great for me too :)
Cheers,
Bruno P. Kinoshita
http://kinoshita.eti.br
http://tupilabs.com
----- Mensagem original -----
> De: Adrian Crum <ad...@sandglass-software.com>
> Para: Commons Developers List <de...@commons.apache.org>
> Cc:
> Enviadas: Terça-feira, 24 de Janeiro de 2012 18:30
> Assunto: Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
>
> On 1/24/2012 8:15 PM, Matt Benson wrote:
>> Thanks for your interest, Adrian! Comments inline:
>>
>> On Tue, Jan 24, 2012 at 1:58 PM, Adrian Crum
>> <ad...@sandglass-software.com> wrote:
>>> On 1/24/2012 6:58 PM, Matt Benson wrote:
>>>> IMO the difference between [lang]'s and [functor]'s range
> concepts is that
>>>> those in [lang] are intended to be able to say whether a given
> value is in
>>>> the Range, but, with the exception of CharRange (this class is not
> even
>>>> public), they make no provision for iterating over members of the
> range. I
>>>> would therefore design a [functor]-targeted Range builder API to
> allow the
>>>> user to specify how next values are obtained. Range may not even be
> the best
>>>> word to describe the behavior we are trying to model here, so
> let's be open
>>>> to reinterpretation as we proceed.
>>>
>>> From my perspective, Range + Step = Sequence.
>> I'll buy that if noone else objects. :)
>>
>>> A Range iterator would be
>>> useful for implementing mathematical sets.
>> e.g. integer range a..b step 3 yields the sequence of integers n
>> greater than or equal to a and less than or equal to b where (n - a) %
>> 3 == 0 ? Is this useful?
>>
>> Matt
>
> It would be useful for a mathematician. Another possibility is a Range
> of Dates, with a step of one hour, or one day or...
>
> The Range class could accept an Iterator factory so various steps can be
> implemented in client code.
>
> -Adrian
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed
intervals
Posted by Adrian Crum <ad...@sandglass-software.com>.
On 1/24/2012 8:15 PM, Matt Benson wrote:
> Thanks for your interest, Adrian! Comments inline:
>
> On Tue, Jan 24, 2012 at 1:58 PM, Adrian Crum
> <ad...@sandglass-software.com> wrote:
>> On 1/24/2012 6:58 PM, Matt Benson wrote:
>>> IMO the difference between [lang]'s and [functor]'s range concepts is that
>>> those in [lang] are intended to be able to say whether a given value is in
>>> the Range, but, with the exception of CharRange (this class is not even
>>> public), they make no provision for iterating over members of the range. I
>>> would therefore design a [functor]-targeted Range builder API to allow the
>>> user to specify how next values are obtained. Range may not even be the best
>>> word to describe the behavior we are trying to model here, so let's be open
>>> to reinterpretation as we proceed.
>>
>> From my perspective, Range + Step = Sequence.
> I'll buy that if noone else objects. :)
>
>> A Range iterator would be
>> useful for implementing mathematical sets.
> e.g. integer range a..b step 3 yields the sequence of integers n
> greater than or equal to a and less than or equal to b where (n - a) %
> 3 == 0 ? Is this useful?
>
> Matt
It would be useful for a mathematician. Another possibility is a Range
of Dates, with a step of one hour, or one day or...
The Range class could accept an Iterator factory so various steps can be
implemented in client code.
-Adrian
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
Posted by Matt Benson <gu...@gmail.com>.
Thanks for your interest, Adrian! Comments inline:
On Tue, Jan 24, 2012 at 1:58 PM, Adrian Crum
<ad...@sandglass-software.com> wrote:
> On 1/24/2012 6:58 PM, Matt Benson wrote:
>>
>> IMO the difference between [lang]'s and [functor]'s range concepts is that
>> those in [lang] are intended to be able to say whether a given value is in
>> the Range, but, with the exception of CharRange (this class is not even
>> public), they make no provision for iterating over members of the range. I
>> would therefore design a [functor]-targeted Range builder API to allow the
>> user to specify how next values are obtained. Range may not even be the best
>> word to describe the behavior we are trying to model here, so let's be open
>> to reinterpretation as we proceed.
>
>
> From my perspective, Range + Step = Sequence.
I'll buy that if noone else objects. :)
> A Range iterator would be
> useful for implementing mathematical sets.
e.g. integer range a..b step 3 yields the sequence of integers n
greater than or equal to a and less than or equal to b where (n - a) %
3 == 0 ? Is this useful?
Matt
>
> -Adrian
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed
intervals
Posted by Adrian Crum <ad...@sandglass-software.com>.
On 1/24/2012 6:58 PM, Matt Benson wrote:
> IMO the difference between [lang]'s and [functor]'s range concepts is
> that those in [lang] are intended to be able to say whether a given
> value is in the Range, but, with the exception of CharRange (this
> class is not even public), they make no provision for iterating over
> members of the range. I would therefore design a [functor]-targeted
> Range builder API to allow the user to specify how next values are
> obtained. Range may not even be the best word to describe the behavior
> we are trying to model here, so let's be open to reinterpretation as
> we proceed.
From my perspective, Range + Step = Sequence. A Range iterator would be
useful for implementing mathematical sets.
-Adrian
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
Posted by "Bruno P. Kinoshita" <br...@yahoo.com.br>.
I've sifted through the archives in commons-dev from ~2002 and found some threads that can be useful regarding the Generators API. I will read it again later to see what I can come up with :) Below are the links and with a short description of each one.
---
Proposal of generators in functor (with attachment)
http://markmail.org/message/rtnn2xpudw3ygtvr
New thread on the same topic
http://markmail.org/message/xainvc6dztvozm63
More on Generator and some discussion on the stoppable behavior, as well as some Java code
http://markmail.org/message/v6jzq436awjmdmth
A message explaining why EachElement wouldn't implement Generator anymore.
http://markmail.org/message/njupdn2i42jit6or
Set of links to other APIs with functors and other reference/resources, probably used while writing the initial code.
http://markmail.org/message/kf7sxy3otspkcesv#query:+page:1+mid:yiysmyaeua6ne4od+state:results
---
Hope that helps.
Bruno P. Kinoshita
http://kinoshita.eti.br
http://tupilabs.com
----- Mensagem original -----
> De: Matt Benson <gu...@gmail.com>
> Para: Bruno P. Kinoshita <br...@yahoo.com.br>; dev@commons.apache.org
> Cc:
> Enviadas: Terça-feira, 24 de Janeiro de 2012 16:58
> Assunto: Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
>
> On Tue, Jan 24, 2012 at 12:37 PM, Bruno P. Kinoshita
> <br...@yahoo.com.br> wrote:
>> Hi Matt,
>>
>>> I think we might do better to handle both tasks by designing a generic
>>> Range builder API, and removing the existing Range classes. This way
>>> either type of bounding could be requested by the user at his
>>> convenience.
>>
>> Great idea Matt. Should we file an issue in JIRA for this?
>
> That would be fine with me; however see my later comments on Ranges
> wrt [functor].
>
>>
>>> Thanks for the publicity (though technically the [functor] component
>>> is Apache *Commons* functor ;) )!
>>
>> Thanks! Updated. :)
>>
>>> Hmm... *which* result is always false? :/
>>
>> Sorry, I didn't make myself clear here. And actually, the issue is not
> that the result is always false, but that IntegerRange .isStopped() and .stop()
> methods are defined in the parent class, BaseGenerator. This way, the following
> code keeps executing, even after you have called stop() method.
>>
>> IntegerRange range = new IntegerRange(0, 11);
>> for(Integer value : range.toCollection()) {
>> range.stop();
>> System.out.println(value);
>> }
>
> Hmm... yes, this doesn't use the Generator API as intended. Calling
> toCollection() runs the entire generator. In this case, however,
> IntegerRange and LongRange are broken in that they never consult
> #isStopped() anyway. I am thinking that we may need to redesign the
> entire Generator API, or scrap it entirely if we can't make it make
> proper sense.
>
>>
>> However, I believe we should follow your suggestion and work designing a
> generic Range builder API. Furthermore, Commons Lang3 has some classes for
> ranges in the trunk too (not sure if all of them were released in 3.1).
>>
>> org.apache.commons.lang3.Range
>> org.apache.commons.lang3.CharRange
>>
>> If I understood correctly, the CharSet will depend on Range to generate
> CharRange's (see LANG-689 and LANG-670), and the CharRange has a
> CharIterator. Looks like maybe we could create Ranges in commons-lang for
> Integer, Long, Float and Double, and remove LongRange and IntegerRange from
> functor. Just food for thought :)
>
> IMO the difference between [lang]'s and [functor]'s range concepts is
> that those in [lang] are intended to be able to say whether a given
> value is in the Range, but, with the exception of CharRange (this
> class is not even public), they make no provision for iterating over
> members of the range. I would therefore design a [functor]-targeted
> Range builder API to allow the user to specify how next values are
> obtained. Range may not even be the best word to describe the
> behavior we are trying to model here, so let's be open to
> reinterpretation as we proceed.
>
>>
>>> I'm not sure we're thinking the exact same thing here, but I do
> like
>>> the idea of moving the stop behavior to a custom Generator wrapper
>>> class. Anything we can do to simplify the Generator API is at least
>>> up for discussion. It's probably one of the least-understood APIs,
> in
>>> all honesty--you must remember that the original developers have long
>>> since disappeared from the Commons community. If you come across any
>>> good FP resources showing you the precedent for [functor]'s
> generator
>>> APIs I'd be glad for more information.
>
> Supporting stop behavior without having it live in the basic Generator
> interface is one reason I suspect it may be necessary to redesign the
> Generator API from the ground up. I still think this sounds like the
> right approach, however.
>
>>
>> I will look for FP resources to see if there is anything that could give us
> more understanding on the Generator API.
>
> I will do the same.
>
> Regards,
> Matt
>
>> This could be useful as documentation in the project website too.
>>
>>> Thanks for your ongoing interest,
>>> Matt
>>
>> Thank you Matt!
>>
>> All the best,
>>
>> Bruno P. Kinoshita
>> http://kinoshita.eti.br
>> http://tupilabs.com
>>
>>
>> ----- Mensagem original -----
>>> De: Matt Benson <gu...@gmail.com>
>>> Para: Commons Developers List <de...@commons.apache.org>; Bruno P.
> Kinoshita <br...@yahoo.com.br>
>>> Cc:
>>> Enviadas: Segunda-feira, 23 de Janeiro de 2012 14:21
>>> Assunto: Re: [functor] CharacterRange, FloatRange, DoubleRange and
> open/closed intervals
>>>
>>> Hi, Bruno; my thoughts inline...
>>>
>>> On Sun, Jan 22, 2012 at 6:15 PM, Bruno P. Kinoshita
>>> <br...@yahoo.com.br> wrote:
>>>> Hi all,
>>>>
>>>> In functor, there are two ranges available: IntegerRange and
> LongRange.
>>> Both use a closed open interval, i.e., the low limit is included in the
> range,
>>> while the high limit is not.
>>>>
>>>> In Perl, we can create a range of numbers too, using the range
> operator
>>> (..). Something like 0..10. What produces a closed interval (both 0 and
> 10 are
>>> included). And in Perl, we can create a range of chars too. Like an
> alphabet,
>>> a..z. Again, a closed interval.
>>>>
>>>> With the current implementation of Ranges in functor, if I want a
> closed
>>> interval from 0 to 10, I have to create the following code (limited by
> 0 and
>>> 11), that produces a closed/open interval.
>>>>
>>>> IntegerRange range = newIntegerRange(0, 11);
>>>>
>>>>
>>>> Now, if I create a CharacterRange, the implementation would have
> to use a
>>> closed interval (otherwise z would never be included).
>>>>
>>>> CharacterRange range = newCharacterRange('a',
> 'z');
>>>>
>>>>
>>>> IMHO, we could change the current implementation, before the first
> release,
>>> to use a closed interval. It means that it would always include the low
> and high
>>> limits. This way, both an IntegerRange and a CharacterRange, would have
> the same
>>> behavior, respecting the Liskov Principle of Substitution. What do you
> think? If
>>> that sounds reasonable, I could file an issue for the change of
> behavior in
>>> JIRA, and another JIRA with an CharacterRange plus tests, and an
> example for the
>>> web site.
>>>>
>>>> Another thing, I have to use float intervals for fuzzy membership
> functions
>>> in a project. As I am already using functor there, I thought I could
> create a
>>> FloatRange and a DoubleRange for functor. What do you think? If this
> sounds good
>>> too, I will file an issue in JIRA for this too, with tests and examples
> for the
>>> web site.
>>>>
>>>
>>> I think we might do better to handle both tasks by designing a generic
>>> Range builder API, and removing the existing Range classes. This way
>>> either type of bounding could be requested by the user at his
>>> convenience.
>>>
>>>>
>>>> I wrote a blog entry to organize my findings while I compared
> functor
>>> ranges with other API's and programming languages, maybe someone
> will find
>>> it interesting
>>> - http://www.kinoshita.eti.br/2012/01/22/ranges-in-apache-functor/
>>>
>>> Thanks for the publicity (though technically the [functor] component
>>> is Apache *Commons* functor ;) )!
>>>
>>>>
>>>> There are other points in Integer and Long ranges that I found
> confusing.
>>> Like, if you call isStopped() before, during the iteration or after you
> iterated
>>> over the elements, the result is always false. Not sure if this is the
> right
>>> behavior for it.
>>>
>>> Hmm... *which* result is always false? :/
>>>
>>>> Perhaps this method could be moved from Generator to a
> StoppableGenerator
>>> interface, that WhileGenerator, GenerateUntil and others would
> implement (maybe
>>> even the IntegerRange, or a StoppableIntegerRange. Try creating a
> IntegerRange
>>> from 0 to Integer.MAX_VALUE and print the values with a
> UnaryProcedure... that
>>> may take some time :)
>>>
>>> I'm not sure we're thinking the exact same thing here, but I do
> like
>>> the idea of moving the stop behavior to a custom Generator wrapper
>>> class. Anything we can do to simplify the Generator API is at least
>>> up for discussion. It's probably one of the least-understood APIs,
> in
>>> all honesty--you must remember that the original developers have long
>>> since disappeared from the Commons community. If you come across any
>>> good FP resources showing you the precedent for [functor]'s
> generator
>>> APIs I'd be glad for more information.
>>>
>>> Thanks for your ongoing interest,
>>> Matt
>>>
>>>>
>>>> Thank you in advance!
>>>>
>>>> Bruno P. Kinoshita
>>>> http://kinoshita.eti.br
>>>> http://tupilabs.com
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
Posted by Matt Benson <gu...@gmail.com>.
On Tue, Jan 24, 2012 at 12:37 PM, Bruno P. Kinoshita
<br...@yahoo.com.br> wrote:
> Hi Matt,
>
>> I think we might do better to handle both tasks by designing a generic
>> Range builder API, and removing the existing Range classes. This way
>> either type of bounding could be requested by the user at his
>> convenience.
>
> Great idea Matt. Should we file an issue in JIRA for this?
That would be fine with me; however see my later comments on Ranges
wrt [functor].
>
>> Thanks for the publicity (though technically the [functor] component
>> is Apache *Commons* functor ;) )!
>
> Thanks! Updated. :)
>
>> Hmm... *which* result is always false? :/
>
> Sorry, I didn't make myself clear here. And actually, the issue is not that the result is always false, but that IntegerRange .isStopped() and .stop() methods are defined in the parent class, BaseGenerator. This way, the following code keeps executing, even after you have called stop() method.
>
> IntegerRange range = new IntegerRange(0, 11);
> for(Integer value : range.toCollection()) {
> range.stop();
> System.out.println(value);
> }
Hmm... yes, this doesn't use the Generator API as intended. Calling
toCollection() runs the entire generator. In this case, however,
IntegerRange and LongRange are broken in that they never consult
#isStopped() anyway. I am thinking that we may need to redesign the
entire Generator API, or scrap it entirely if we can't make it make
proper sense.
>
> However, I believe we should follow your suggestion and work designing a generic Range builder API. Furthermore, Commons Lang3 has some classes for ranges in the trunk too (not sure if all of them were released in 3.1).
>
> org.apache.commons.lang3.Range
> org.apache.commons.lang3.CharRange
>
> If I understood correctly, the CharSet will depend on Range to generate CharRange's (see LANG-689 and LANG-670), and the CharRange has a CharIterator. Looks like maybe we could create Ranges in commons-lang for Integer, Long, Float and Double, and remove LongRange and IntegerRange from functor. Just food for thought :)
IMO the difference between [lang]'s and [functor]'s range concepts is
that those in [lang] are intended to be able to say whether a given
value is in the Range, but, with the exception of CharRange (this
class is not even public), they make no provision for iterating over
members of the range. I would therefore design a [functor]-targeted
Range builder API to allow the user to specify how next values are
obtained. Range may not even be the best word to describe the
behavior we are trying to model here, so let's be open to
reinterpretation as we proceed.
>
>> I'm not sure we're thinking the exact same thing here, but I do like
>> the idea of moving the stop behavior to a custom Generator wrapper
>> class. Anything we can do to simplify the Generator API is at least
>> up for discussion. It's probably one of the least-understood APIs, in
>> all honesty--you must remember that the original developers have long
>> since disappeared from the Commons community. If you come across any
>> good FP resources showing you the precedent for [functor]'s generator
>> APIs I'd be glad for more information.
Supporting stop behavior without having it live in the basic Generator
interface is one reason I suspect it may be necessary to redesign the
Generator API from the ground up. I still think this sounds like the
right approach, however.
>
> I will look for FP resources to see if there is anything that could give us more understanding on the Generator API.
I will do the same.
Regards,
Matt
> This could be useful as documentation in the project website too.
>
>> Thanks for your ongoing interest,
>> Matt
>
> Thank you Matt!
>
> All the best,
>
> Bruno P. Kinoshita
> http://kinoshita.eti.br
> http://tupilabs.com
>
>
> ----- Mensagem original -----
>> De: Matt Benson <gu...@gmail.com>
>> Para: Commons Developers List <de...@commons.apache.org>; Bruno P. Kinoshita <br...@yahoo.com.br>
>> Cc:
>> Enviadas: Segunda-feira, 23 de Janeiro de 2012 14:21
>> Assunto: Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
>>
>> Hi, Bruno; my thoughts inline...
>>
>> On Sun, Jan 22, 2012 at 6:15 PM, Bruno P. Kinoshita
>> <br...@yahoo.com.br> wrote:
>>> Hi all,
>>>
>>> In functor, there are two ranges available: IntegerRange and LongRange.
>> Both use a closed open interval, i.e., the low limit is included in the range,
>> while the high limit is not.
>>>
>>> In Perl, we can create a range of numbers too, using the range operator
>> (..). Something like 0..10. What produces a closed interval (both 0 and 10 are
>> included). And in Perl, we can create a range of chars too. Like an alphabet,
>> a..z. Again, a closed interval.
>>>
>>> With the current implementation of Ranges in functor, if I want a closed
>> interval from 0 to 10, I have to create the following code (limited by 0 and
>> 11), that produces a closed/open interval.
>>>
>>> IntegerRange range = newIntegerRange(0, 11);
>>>
>>>
>>> Now, if I create a CharacterRange, the implementation would have to use a
>> closed interval (otherwise z would never be included).
>>>
>>> CharacterRange range = newCharacterRange('a', 'z');
>>>
>>>
>>> IMHO, we could change the current implementation, before the first release,
>> to use a closed interval. It means that it would always include the low and high
>> limits. This way, both an IntegerRange and a CharacterRange, would have the same
>> behavior, respecting the Liskov Principle of Substitution. What do you think? If
>> that sounds reasonable, I could file an issue for the change of behavior in
>> JIRA, and another JIRA with an CharacterRange plus tests, and an example for the
>> web site.
>>>
>>> Another thing, I have to use float intervals for fuzzy membership functions
>> in a project. As I am already using functor there, I thought I could create a
>> FloatRange and a DoubleRange for functor. What do you think? If this sounds good
>> too, I will file an issue in JIRA for this too, with tests and examples for the
>> web site.
>>>
>>
>> I think we might do better to handle both tasks by designing a generic
>> Range builder API, and removing the existing Range classes. This way
>> either type of bounding could be requested by the user at his
>> convenience.
>>
>>>
>>> I wrote a blog entry to organize my findings while I compared functor
>> ranges with other API's and programming languages, maybe someone will find
>> it interesting
>> - http://www.kinoshita.eti.br/2012/01/22/ranges-in-apache-functor/
>>
>> Thanks for the publicity (though technically the [functor] component
>> is Apache *Commons* functor ;) )!
>>
>>>
>>> There are other points in Integer and Long ranges that I found confusing.
>> Like, if you call isStopped() before, during the iteration or after you iterated
>> over the elements, the result is always false. Not sure if this is the right
>> behavior for it.
>>
>> Hmm... *which* result is always false? :/
>>
>>> Perhaps this method could be moved from Generator to a StoppableGenerator
>> interface, that WhileGenerator, GenerateUntil and others would implement (maybe
>> even the IntegerRange, or a StoppableIntegerRange. Try creating a IntegerRange
>> from 0 to Integer.MAX_VALUE and print the values with a UnaryProcedure... that
>> may take some time :)
>>
>> I'm not sure we're thinking the exact same thing here, but I do like
>> the idea of moving the stop behavior to a custom Generator wrapper
>> class. Anything we can do to simplify the Generator API is at least
>> up for discussion. It's probably one of the least-understood APIs, in
>> all honesty--you must remember that the original developers have long
>> since disappeared from the Commons community. If you come across any
>> good FP resources showing you the precedent for [functor]'s generator
>> APIs I'd be glad for more information.
>>
>> Thanks for your ongoing interest,
>> Matt
>>
>>>
>>> Thank you in advance!
>>>
>>> Bruno P. Kinoshita
>>> http://kinoshita.eti.br
>>> http://tupilabs.com
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
Posted by "Bruno P. Kinoshita" <br...@yahoo.com.br>.
Hi Matt,
> I think we might do better to handle both tasks by designing a generic
> Range builder API, and removing the existing Range classes. This way
> either type of bounding could be requested by the user at his
> convenience.
Great idea Matt. Should we file an issue in JIRA for this?
> Thanks for the publicity (though technically the [functor] component
> is Apache *Commons* functor ;) )!
Thanks! Updated. :)
> Hmm... *which* result is always false? :/
Sorry, I didn't make myself clear here. And actually, the issue is not that the result is always false, but that IntegerRange .isStopped() and .stop() methods are defined in the parent class, BaseGenerator. This way, the following code keeps executing, even after you have called stop() method.
IntegerRange range = new IntegerRange(0, 11);
for(Integer value : range.toCollection()) {
range.stop();
System.out.println(value);
}
However, I believe we should follow your suggestion and work designing a generic Range builder API. Furthermore, Commons Lang3 has some classes for ranges in the trunk too (not sure if all of them were released in 3.1).
org.apache.commons.lang3.Range
org.apache.commons.lang3.CharRange
If I understood correctly, the CharSet will depend on Range to generate CharRange's (see LANG-689 and LANG-670), and the CharRange has a CharIterator. Looks like maybe we could create Ranges in commons-lang for Integer, Long, Float and Double, and remove LongRange and IntegerRange from functor. Just food for thought :)
> I'm not sure we're thinking the exact same thing here, but I do like
> the idea of moving the stop behavior to a custom Generator wrapper
> class. Anything we can do to simplify the Generator API is at least
> up for discussion. It's probably one of the least-understood APIs, in
> all honesty--you must remember that the original developers have long
> since disappeared from the Commons community. If you come across any
> good FP resources showing you the precedent for [functor]'s generator
> APIs I'd be glad for more information.
I will look for FP resources to see if there is anything that could give us more understanding on the Generator API. This could be useful as documentation in the project website too.
> Thanks for your ongoing interest,
> Matt
Thank you Matt!
All the best,
Bruno P. Kinoshita
http://kinoshita.eti.br
http://tupilabs.com
----- Mensagem original -----
> De: Matt Benson <gu...@gmail.com>
> Para: Commons Developers List <de...@commons.apache.org>; Bruno P. Kinoshita <br...@yahoo.com.br>
> Cc:
> Enviadas: Segunda-feira, 23 de Janeiro de 2012 14:21
> Assunto: Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
>
> Hi, Bruno; my thoughts inline...
>
> On Sun, Jan 22, 2012 at 6:15 PM, Bruno P. Kinoshita
> <br...@yahoo.com.br> wrote:
>> Hi all,
>>
>> In functor, there are two ranges available: IntegerRange and LongRange.
> Both use a closed open interval, i.e., the low limit is included in the range,
> while the high limit is not.
>>
>> In Perl, we can create a range of numbers too, using the range operator
> (..). Something like 0..10. What produces a closed interval (both 0 and 10 are
> included). And in Perl, we can create a range of chars too. Like an alphabet,
> a..z. Again, a closed interval.
>>
>> With the current implementation of Ranges in functor, if I want a closed
> interval from 0 to 10, I have to create the following code (limited by 0 and
> 11), that produces a closed/open interval.
>>
>> IntegerRange range = newIntegerRange(0, 11);
>>
>>
>> Now, if I create a CharacterRange, the implementation would have to use a
> closed interval (otherwise z would never be included).
>>
>> CharacterRange range = newCharacterRange('a', 'z');
>>
>>
>> IMHO, we could change the current implementation, before the first release,
> to use a closed interval. It means that it would always include the low and high
> limits. This way, both an IntegerRange and a CharacterRange, would have the same
> behavior, respecting the Liskov Principle of Substitution. What do you think? If
> that sounds reasonable, I could file an issue for the change of behavior in
> JIRA, and another JIRA with an CharacterRange plus tests, and an example for the
> web site.
>>
>> Another thing, I have to use float intervals for fuzzy membership functions
> in a project. As I am already using functor there, I thought I could create a
> FloatRange and a DoubleRange for functor. What do you think? If this sounds good
> too, I will file an issue in JIRA for this too, with tests and examples for the
> web site.
>>
>
> I think we might do better to handle both tasks by designing a generic
> Range builder API, and removing the existing Range classes. This way
> either type of bounding could be requested by the user at his
> convenience.
>
>>
>> I wrote a blog entry to organize my findings while I compared functor
> ranges with other API's and programming languages, maybe someone will find
> it interesting
> - http://www.kinoshita.eti.br/2012/01/22/ranges-in-apache-functor/
>
> Thanks for the publicity (though technically the [functor] component
> is Apache *Commons* functor ;) )!
>
>>
>> There are other points in Integer and Long ranges that I found confusing.
> Like, if you call isStopped() before, during the iteration or after you iterated
> over the elements, the result is always false. Not sure if this is the right
> behavior for it.
>
> Hmm... *which* result is always false? :/
>
>> Perhaps this method could be moved from Generator to a StoppableGenerator
> interface, that WhileGenerator, GenerateUntil and others would implement (maybe
> even the IntegerRange, or a StoppableIntegerRange. Try creating a IntegerRange
> from 0 to Integer.MAX_VALUE and print the values with a UnaryProcedure... that
> may take some time :)
>
> I'm not sure we're thinking the exact same thing here, but I do like
> the idea of moving the stop behavior to a custom Generator wrapper
> class. Anything we can do to simplify the Generator API is at least
> up for discussion. It's probably one of the least-understood APIs, in
> all honesty--you must remember that the original developers have long
> since disappeared from the Commons community. If you come across any
> good FP resources showing you the precedent for [functor]'s generator
> APIs I'd be glad for more information.
>
> Thanks for your ongoing interest,
> Matt
>
>>
>> Thank you in advance!
>>
>> Bruno P. Kinoshita
>> http://kinoshita.eti.br
>> http://tupilabs.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [functor] CharacterRange, FloatRange, DoubleRange and open/closed intervals
Posted by Matt Benson <gu...@gmail.com>.
Hi, Bruno; my thoughts inline...
On Sun, Jan 22, 2012 at 6:15 PM, Bruno P. Kinoshita
<br...@yahoo.com.br> wrote:
> Hi all,
>
> In functor, there are two ranges available: IntegerRange and LongRange. Both use a closed open interval, i.e., the low limit is included in the range, while the high limit is not.
>
> In Perl, we can create a range of numbers too, using the range operator (..). Something like 0..10. What produces a closed interval (both 0 and 10 are included). And in Perl, we can create a range of chars too. Like an alphabet, a..z. Again, a closed interval.
>
> With the current implementation of Ranges in functor, if I want a closed interval from 0 to 10, I have to create the following code (limited by 0 and 11), that produces a closed/open interval.
>
> IntegerRange range = newIntegerRange(0, 11);
>
>
> Now, if I create a CharacterRange, the implementation would have to use a closed interval (otherwise z would never be included).
>
> CharacterRange range = newCharacterRange('a', 'z');
>
>
> IMHO, we could change the current implementation, before the first release, to use a closed interval. It means that it would always include the low and high limits. This way, both an IntegerRange and a CharacterRange, would have the same behavior, respecting the Liskov Principle of Substitution. What do you think? If that sounds reasonable, I could file an issue for the change of behavior in JIRA, and another JIRA with an CharacterRange plus tests, and an example for the web site.
>
> Another thing, I have to use float intervals for fuzzy membership functions in a project. As I am already using functor there, I thought I could create a FloatRange and a DoubleRange for functor. What do you think? If this sounds good too, I will file an issue in JIRA for this too, with tests and examples for the web site.
>
I think we might do better to handle both tasks by designing a generic
Range builder API, and removing the existing Range classes. This way
either type of bounding could be requested by the user at his
convenience.
>
> I wrote a blog entry to organize my findings while I compared functor ranges with other API's and programming languages, maybe someone will find it interesting - http://www.kinoshita.eti.br/2012/01/22/ranges-in-apache-functor/
Thanks for the publicity (though technically the [functor] component
is Apache *Commons* functor ;) )!
>
> There are other points in Integer and Long ranges that I found confusing. Like, if you call isStopped() before, during the iteration or after you iterated over the elements, the result is always false. Not sure if this is the right behavior for it.
Hmm... *which* result is always false? :/
> Perhaps this method could be moved from Generator to a StoppableGenerator interface, that WhileGenerator, GenerateUntil and others would implement (maybe even the IntegerRange, or a StoppableIntegerRange. Try creating a IntegerRange from 0 to Integer.MAX_VALUE and print the values with a UnaryProcedure... that may take some time :)
I'm not sure we're thinking the exact same thing here, but I do like
the idea of moving the stop behavior to a custom Generator wrapper
class. Anything we can do to simplify the Generator API is at least
up for discussion. It's probably one of the least-understood APIs, in
all honesty--you must remember that the original developers have long
since disappeared from the Commons community. If you come across any
good FP resources showing you the precedent for [functor]'s generator
APIs I'd be glad for more information.
Thanks for your ongoing interest,
Matt
>
> Thank you in advance!
>
> Bruno P. Kinoshita
> http://kinoshita.eti.br
> http://tupilabs.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org