Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Daniel Strobusch via swift-users
I think excluding the upper bound (..<) does not address the problem correctly. The problem occurs on including the upper bound. Consider the following simple program #!/usr/bin/env swift if let n: UInt8 = UInt8(Process.arguments[1]) { for i in 0...n { print (i) } } this

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Dave Abrahams via swift-users
on Fri Apr 08 2016, Erica Sadun wrote: > On Apr 8, 2016, at 3:48 AM, tuuranton--- via swift-users > wrote: > > print(UInt8.min) //0 > > print(UInt8.max) //255 > > //Is there an easy way to loop between all values > > //between (and including both) UInt8.min and U

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Cody Weaver via swift-users
I think an easy answer if I understand the question right is. let a: UInt8 = UInt8.min let b = UInt8 = UInt8.max for c in a.. wrote: > Hi, > just as a side note, I filed a bug on this some time ago: > > https://bugs.swift.org/browse/SR-1091 > > so let’s hope, this gets fixed in Swift3. Its reall

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Daniel Strobusch via swift-users
Hi, just as a side note, I filed a bug on this some time ago: https://bugs.swift.org/browse/SR-1091 so let’s hope, this gets fixed in Swift3. Its really annoying and dangerous because the error is not recovered at compile time. Daniel ___ swift-use

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Dmitri Gribenko via swift-users
On Fri, Apr 8, 2016 at 2:48 AM, tuuranton--- via swift-users wrote: > print(UInt8.min) //0 > > print(UInt8.max) //255 > > > //Is there an easy way to loop between all values > > //between (and including both) UInt8.min and UInt8.max? > > > //This doesn't work. > > //Runtime crash because UInt8.max

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Adriano Ferreira via swift-users
Hi Milos, Thanks for getting back to me this quickly. Well, this part specifically was more of a curiosity based on Jens’ comment: “If Limb is a Component, then a Spider entity needs eight of them…” I also confess I’m unsure about this… so please don’t bother then. Looking forward to hearing y

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Milos Rankovic via swift-users
> “If Limb is a Component, then a Spider entity needs eight of them…” That’s a fair question to ask. My intuition is that sporting a `Component` answers a question, “does it have this feature?” In the case of self-propelling creatures, you’d probably ask, “does it have legs”. On the other hand,

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Adriano Ferreira via swift-users
Milos, Thanks for taking a look at it, I appreciate you suggestion. It’s protocol-oriented, quite different from the idea I was trying to emulate — the one provided by GameplayKit. Well, I tried it and it works great. Now, would you implement those methods differently? mutating func add(comp

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Nate Cook via swift-users
You can stride through the maximum value of a type if you land right on it: for i in UInt8.min.stride(through: UInt8.max, by: 1) { print(i) } Nate > On Apr 8, 2016, at 9:21 AM, Erica Sadun wrote: > > >> On Apr 8, 2016, at 3:48 AM, tuuranton--- via swift-users >> wrote: >> >> print(UInt

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Milos Rankovic via swift-users
> On 8 Apr 2016, at 15:12, Adriano Ferreira wrote: > > Milos, > > Thanks for taking a look at it, I appreciate you suggestion. > > It’s protocol-oriented, quite different from the idea I was trying to emulate > — the one provided by GameplayKit. > > Well, I tried it and it works great. Thou

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Milos Rankovic via swift-users
My message bounced on account of size. I’m sorry if you receive multiple copies of this: > “If Limb is a Component, then a Spider entity needs eight of them…” That’s a fair question to ask. My intuition is that sporting a `Component` answers a question, “does it have this feature?” In the case

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Milos Rankovic via swift-users
Hi Adriano, I’m glad if you are finding this useful. I’ll get back to you on `add` and `remove`, but just let me confirm with you: You actually want to allow multiple, say, `Health` components to be added to your `Character`? Most of the complication in my suggested code comes from trying to pr

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Erica Sadun via swift-users
It's a really good corner case to consider if you're thinking about redesigning ranges though. -- E > On Apr 8, 2016, at 8:43 AM, Nate Cook wrote: > > You can stride through the maximum value of a type if you land right on it: > > for i in UInt8.min.stride(through: UInt8.max, by: 1) { > pr

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Milos Rankovic via swift-users
Hi Erica, Wouldn’t this work for @tuuranton’s purposes? let allUInt8s = UInt8.min.stride(through: UInt8.max, by: 1) allUInt8s.dynamicType // StrideThrough.Type Array(allUInt8s).count // 256 for i in allUInt8s { i // 0...255 } milos > On 8 Apr 2016, at 13:48, tuuranton--- via swift-

[swift-users] Swift on RedHat

2016-04-08 Thread John Smith via swift-users
Does anyone know if there is a swift for RedHat distro available? I tried to mash together some instructions for installing on ubuntu but have not been successful. Thanks, Bruce ___ swift-users mailing list swift-users@swift.org https://lists.swift.org

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Erica Sadun via swift-users
> On Apr 8, 2016, at 3:48 AM, tuuranton--- via swift-users > wrote: > > print(UInt8.min) //0 > > print(UInt8.max) //255 > > > > //Is there an easy way to loop between all values > > //between (and including both) UInt8.min and UInt8.max? > > > > //This doesn't work. > > //Runtime crash

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Milos Rankovic via swift-users
In that case, at least make it lazy: let allUInt8s = UInt8.min.stride(through: UInt8.max, by: 1) allUInt8s.dynamicType // StrideThrough.Type Array(allUInt8s).count // 256 for i in allUInt8s { i // 0...255 } milos > On 8 Apr 2016, at 13:48, tuuranton--- via swift-users > wrote: > >

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread tuuranton--- via swift-users
The problem with both solutions is that I lose the type information. Instead of i being UInt8 it is Int or UInt. This is one solution I came up with: extension UInt8 {    static var allValues: [UInt8] {        var v: [UInt8] = []        for i in 0.. You could cast the min and max values to an Int

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Peter Vertes via swift-users
You could cast the min and max values to an Int and iterate through the Int range: let min = Int(UInt8.min) let max = Int(UInt8.max) for i in min...max { print(i) } While this will work it seems like a hack to me and Milos’ solution is more elegant… -Pete > On Apr 8, 2016, at 5:50 AM, t

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Milos Rankovic via swift-users
Would this work for you? extension UInt8 { var u: UInt { return UInt(self) } } for i in UInt8.min.u...UInt8.max.u { print(i) } milos > On 8 Apr 2016, at 10:50, tuuranton--- via swift-users > wrote: > > I forgot to mention that I really would like to have i have type UInt8 wi

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Milos Rankovic via swift-users
A type-uniquing alternative (see my previous message): // Swift 2.2 // Entity-Component System (sketch): protocol Component { static var name: String { get } // not necessary (see comments below) } extension Component { // can be overridden with `let` by conforming types

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Milos Rankovic via swift-users
This is just a sketch. There may be issues down the line (I’ve indicated some with `TODO`s), but it works and you can try it in the playground: // Swift 2.2 // utility: extension Array { func first (_: T.Type) -> T? { for e in self where e is T { return e as? T }

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread tuuranton--- via swift-users
I forgot to mention that I really would like to have i have type UInt8 within the loop. And since i is UInt8 it makes sense it should be able to take the values UInt8.min and UInt8.max (and all the values between). 8. Apr 2016 11:48 by swift-users@swift.org: > > print(UInt8.min) //0 > > print(

[swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread tuuranton--- via swift-users
print(UInt8.min) //0 print(UInt8.max) //255 //Is there an easy way to loop between all values //between (and including both) UInt8.min and UInt8.max? //This doesn't work. //Runtime crash because UInt8.max has no successor. for i in UInt8.min...UInt8.max {     print(i) }