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
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
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
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
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
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
> “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,
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
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
> 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
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
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
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
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-
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
> 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
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:
>
>
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
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
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
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
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 }
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(
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)
}
24 matches
Mail list logo