uqbar-project / wollok

Wollok Programming Language
GNU General Public License v3.0
60 stars 16 forks source link

Range doesn't have any, all, fold methods of Collection #730

Closed fdodino closed 8 years ago

fdodino commented 8 years ago

It would be very useful to use them, like in prime() definition of Wollok Integers. Otherwise I have to code

        method prime() {
            if (self == 1) return false
            var isPrime = true
            (2..self - 1).forEach({ i =>
                // Horrible definition, but return doesn't exit from loop
                // and I need fold, any methods in Range
                if(self % i == 0) isPrime = false 
            })
            return isPrime
        }
flbulgarelli commented 8 years ago

I was wondering this is a similar issue yo what happens on strings.

Se could implement it using nixins to avoid logic repetition .

I reported an issue about adding an enunerable protocol some months ago.

However, un both cases a asList method could solve most of the usescases, right?

fdodino commented 8 years ago

Implemented a toList() method in Range, I sent a mail a few hours ago...

flbulgarelli commented 8 years ago

Hi @fdodino

I was noticing that we don't have a good convention for conversion methods. Some of them are toXYZ (like toString) and others are asXYZ like asSet.

We should define a convention and stick to it.

See #735

npasserini commented 8 years ago

Strings are a bit more complicated, because the will force us to introduce characters as a data type.

I think that Strings have inherently different operations than collections, I don't see why we would do a map or filter... it seems weird and it complicates a very common object that I would prefer to keep simple.

+1 to the mixin idea.

On Sat, Jun 11, 2016 at 5:24 PM, Franco Leonardo Bulgarelli < notifications@github.com> wrote:

I was wondering this is a similar issue yo what happens on strings.

Se could implement it using nixins to avoid logic repetition .

I reported an issue about adding an enunerable protocol some months ago.

However, un both cases a asList method could solve most of the usescases, right?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/uqbar-project/wollok/issues/730#issuecomment-225369694, or mute the thread https://github.com/notifications/unsubscribe/AEa1OTjbgWVLpEkPvYVYz6Bvz30_GenUks5qKtM0gaJpZM4IzkHp .

fdodino commented 8 years ago

I'm closing this issue. Please @flbulgarelli add a new issue to complete the task by defining a mixin between collections and ranges.