Re: [swift-users] Zero cost abstraction 2D Iterator (equivalent to two nested for loops) impossible?

2017-01-04 Thread Karl via swift-users
Hmmm that’s interesting. A brief test I ran: import CoreGraphics import Foundation struct PointIterator { let rect: CGRect var nextPoint: CGPoint let maxX: CGFloat let maxY: CGFloat init(rect: CGRect) { self.rect = rect.standardized self.nextPoint = self.rect.origin /

Re: [swift-users] SwiftPM: import ncurses -> conflicting types

2017-01-02 Thread Karl via swift-users
It’s even easier than that… import Darwin.ncurses ;) - Karl > On 29 Dec 2016, at 06:23, Ankit Aggarwal via swift-users > wrote: > > ncurses is already present in the macOS sdk, so you don't need to install it > via brew. > > In CNCurses package, create a file called "shim.h": > $ cat shim.h

Re: [swift-users] Extending Arrays of specific type, and specialization

2016-11-25 Thread Karl via swift-users
> On 23 Nov 2016, at 01:50, Hooman Mehr via swift-users > wrote: > > For example, this reduces the six variants of sum to two: > > public protocol ContiguousBufferedArray: RandomAccessCollection { > > func withUnsafeBufferPointer(_ body: > (UnsafeBufferPointer) throws -> R) rethrows

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Karl via swift-users
> On 18 Nov 2016, at 20:18, John McCall wrote: > >> >> On Nov 18, 2016, at 7:40 AM, Karl > > wrote: >> >> >>> On 18 Nov 2016, at 13:05, Adrian Zubarev via swift-users >>> mailto:swift-users@swift.org>> wrote: >>> >>> Hi there, >>> >>> I just can’t get my head aro

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Karl via swift-users
> On 18 Nov 2016, at 16:40, Karl wrote: > > >> On 18 Nov 2016, at 13:05, Adrian Zubarev via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> Hi there, >> >> I just can’t get my head around mutable views and COW. >> >> Here is a small example: >> >> final class Storage { >>

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Karl via swift-users
> On 18 Nov 2016, at 13:05, Adrian Zubarev via swift-users > wrote: > > Hi there, > > I just can’t get my head around mutable views and COW. > > Here is a small example: > > final class Storage { > > var keys: [String] = [] > var values: [Int] = [] > } > > public struct Docume

Re: [swift-users] dispatch concurrent map: is this right?

2016-10-31 Thread Karl via swift-users
> On 31 Oct 2016, at 05:15, Dave Abrahams wrote: > > > on Sun Oct 30 2016, Karl > wrote: > >>> On 30 Oct 2016, at 19:23, Dave Abrahams via swift-users >>> wrote: >>> >>> >>> on Sun Oct 30 2016, Karl wrote: >>> >> > On 30 Oct 2016, at 09:15, Karl wrot

Re: [swift-users] dispatch concurrent map: is this right?

2016-10-30 Thread Karl via swift-users
> On 30 Oct 2016, at 19:23, Dave Abrahams via swift-users > wrote: > > > on Sun Oct 30 2016, Karl wrote: > >>> On 30 Oct 2016, at 09:15, Karl wrote: >>> >>> I had the need for a concurrent map recently. I had a part of a >>> program which needed to read chunks of data and concurrently proc

Re: [swift-users] dispatch concurrent map: is this right?

2016-10-30 Thread Karl via swift-users
> On 30 Oct 2016, at 09:15, Karl wrote: > > I had the need for a concurrent map recently. I had a part of a program which > needed to read chunks of data and concurrently process them and assemble the > results in an array. This isn’t necessarily as obvious as it sounds, because > of arrays b

[swift-users] dispatch concurrent map: is this right?

2016-10-30 Thread Karl via swift-users
I had the need for a concurrent map recently. I had a part of a program which needed to read chunks of data and concurrently process them and assemble the results in an array. This isn’t necessarily as obvious as it sounds, because of arrays being value types. I came up with the following snippe

Re: [swift-users] Cross-Compiling to Linux from macOS

2016-09-21 Thread Karl via swift-users
> On 21 Sep 2016, at 19:14, Rafael Costa via swift-users > wrote: > > Hello fellow Swift users, > > I’m encountering some problems and I wish to know if anyone here has ever > come across something similar. > > In essence, I want to cross-compile a Swift Project on macOS to run it on > Linu

Re: [swift-users] Cross-Compiling to Linux from macOS

2016-09-21 Thread Karl via swift-users
> On 21 Sep 2016, at 19:14, Rafael Costa via swift-users > wrote: > > Hello fellow Swift users, > > I’m encountering some problems and I wish to know if anyone here has ever > come across something similar. > > In essence, I want to cross-compile a Swift Project on macOS to run it on > Linu

Re: [swift-users] Weak references in generic types

2016-08-31 Thread Karl via swift-users
> On 1 Sep 2016, at 03:23, Howard Lovatt via swift-users > wrote: > > Playing around I found that if you make the protocol @objc instead of > AnyObject then it works :). EG: > > struct WeakReference { > weak var value: T? > } > @objc protocol P { // Note @objc, class or AnyObject does not

Re: [swift-users] Implicitly type conversion ?

2016-08-25 Thread Karl via swift-users
> On 19 Aug 2016, at 18:00, Tim Vermeulen via swift-users > wrote: > > Any idea why Swift supports implicit casting to AnyHashable, but not to, say, > AnySequence? > It’s a hack until existential support gets better. Explicitly casting to AnyHashable clutters your dictionary literals. Ther

[swift-users] How to build a CLI tool which links a Swift framework? (OSX)

2016-08-25 Thread Karl via swift-users
Hi I’ve got a cross-platform Swift framework which is used in a project, and I want to make a CLI tool which also uses it. I’m having a problem getting the framework and CLI tool to work together, because of the Swift standard libraries: [1] If I just create a new CLI app and link it to my fra

Re: [swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-09 Thread Karl via swift-users
> On 3 Aug 2016, at 02:01, Rick Mann via swift-users > wrote: > > It complains if I make it a let because computed properties must be var. > Because it's a protocol, it can't be stored (even though it can be stored in > the conforming type). > > If I make it { get }, I can't set it in the ex

[swift-users] Are typealiases within protocols supposed to be visible from conforming types?

2016-08-03 Thread Karl via swift-users
Straightforward question - Are typealiases within protocols supposed to be visible from conforming types? For example: > protocol MyProto { > > typealias ComplexFunctionType = (_ paramOne: (Int, Bool?), _ paramTwo: > (Bool, String?, String)) throws -> (Array, Float)? > > fun

Re: [swift-users] Why can't structs inherit from other structs?

2016-08-02 Thread Karl via swift-users
> * Structs have statically-dispatched methods and properties; there's no > ability to override. > I wonder if that is an inherent property of structs, or a side-effect from them having no inheritance. There is no way to define something else which also “is” a CGRect, so all structs are fina

Re: [swift-users] More questions about protocol/value programming

2016-08-01 Thread Karl via swift-users
A protocol can require that a certain initialiser exists, but it can’t provide a default implementation (you can add initialisers in a protocol extension IIRC, but then they must delegate to an actual, required initialiser). A protocol is not the same thing as a subclass. Any type could conform

Re: [swift-users] Can't initialise using a UTF8 string from within 'withUnsafeBufferPointer' expression

2016-07-18 Thread Karl via swift-users
> On 18 Jul 2016, at 14:51, Martin R wrote: > > This is not an answer to your question, but note that you can pass a Swift > String to functions expecting an UnsafePointer (C String) parameter, > and the compiler will generate a temporary NUL-terminated UTF-8 > representation for you: > > l

[swift-users] Can't initialise using a UTF8 string from within 'withUnsafeBufferPointer' expression

2016-07-17 Thread Karl via swift-users
As I understand it, we are supposed to use withUnsafe{Mutable/Buffer}Pointer or withExtendedLifetime to guarantee that objects we take pointers of will exist and won’t be optimised out by the compiler. However, this leads to a problem when trying to initialise something which expects a UTF8 str

[swift-users] How do you use protocol types?

2016-07-13 Thread Karl via swift-users
So I’m trying to work generically to construct things based on their conformance to a protocol with an initialiser. I’m sure this worked before; I’ve done it before. Maybe there have been some changes in the language or something, because I’ve tried everywhich-way and this just isn’t flying: ==

Re: [swift-users] lazy initialisation

2016-07-09 Thread Karl via swift-users
> On 9 Jul 2016, at 06:34, Zhao Xin wrote: > > The compiler is not smart enough to treat this as you think, nor it will be > designed to. According to the documents, it is the developer‘s burden ​to add > @noescape or weak or unowned. So I disagree it is a bug. > > Zhaoxin > > On Sat, Jul 9,

Re: [swift-users] lazy initialisation

2016-07-08 Thread Karl via swift-users
> On 5 Jul 2016, at 03:47, Zhao Xin wrote: > > No, it is not a bug. > > For a closure, you have to call self explicitly unless the closure is mark as > @noescape. Also, in this situation, self is not unowned, as the closure is > not stored, it ran and released. Below, is a situation that you

Re: [swift-users] [Bug or ByDesign?] unowned optional values not allowed

2016-07-06 Thread Karl via swift-users
> On 5 Jul 2016, at 18:21, Jordan Rose wrote: > > Longstanding bug, rdar://problem/17277899 . > Surprisingly few people have asked for it. > > Jordan > Good to know, thanks. Maybe not enough people know/care about the overheads of weak references? Since the WWDC Swift performance talk I’ve

Re: [swift-users] lazy initialisation

2016-07-04 Thread Karl via swift-users
> On 4 Jul 2016, at 21:12, Mark Dalrymple via swift-users > wrote: > > Here's the one I started with: > >lazy var c:Int = {return a*b}() > > and ended up with: > > lazy var c:Int = {return self.a * self.b}() > > It's in a closure, so need to explicitly reference self. > > Cheers, >

[swift-users] [Bug or ByDesign?] unowned optional values not allowed

2016-07-03 Thread Karl via swift-users
Currently it’s not possible to have an unowned optional value. E.g: class A { unowned var parent : A? // ‘unowned’ may only be applied to class and class-bound protocol types, not ‘A?' deinit { if let p = parent { print("Bye, mom!") } print("dealloca

Re: [swift-users] [Possible bug] Initialising multiple instance variables from a closure

2016-06-29 Thread Karl via swift-users
Oh, I figured it out. The syntax is a bit strange, but after enough attempts I ended up at this: let (toolbar, aButton) : (UIToolbar, UIBarButtonItem) = { let toolbar = UIToolbar() let aButton = UIBarButtonItem() return (toolbar, aButton)

[swift-users] [Possible bug] Initialising multiple instance variables from a closure

2016-06-29 Thread Karl via swift-users
Currently you can initialise a class instance variable from a closure: let textView : UITextView = { let t = UITextView() t.translatesAutoresizingMaskIntoConstraints = false t.autocapitalizationType = .none t.autocorrectionType = .no

Re: [swift-users] When does `Data.init?(capacity:)` fail?

2016-06-19 Thread Karl via swift-users
As I understand it, that’s not an error in the ‘try’ sense of the word. If that failure happens, it’s a catastrophic issue which should bring down the application. So the initialiser shouldn’t be failable; you’re right. File a bug at bugs.swift.org. Karl > On 18 Jun 2016, at 06:06, Saagar Jha

Re: [swift-users] SequenceType vs. CollectionType

2016-06-16 Thread Karl via swift-users
> On 15 Jun 2016, at 01:59, Brent Royal-Gordon via swift-users > wrote: > >> I find the SequenceType protocol a bit confusing. My confusion is best >> explained in the context of a specific, real-world example. Let's say that >> I wanted to extend a protocol with a method "repeated(Int)" th

Re: [swift-users] Usage of final let?

2016-06-13 Thread Karl via swift-users
Welcome! That’s a fair point; “final let” doesn’t make sense. You should file a bug report on https://bugs.swift.org Karl > On 13 Jun 2016, at 07:43, Azuan via swift-users wrote: > > Hi, > > This is my first email to this mailing list. Do correct me if I did something > wrong :) > > Read i

Re: [swift-users] build-script error

2016-06-10 Thread Karl via swift-users
i686 is a 32-bit system, right? We don’t support Intel 32-bit on Linux (yet?). The only Intel Linux target is x86_64. > On 10 Jun 2016, at 20:18, Jeff Ramsey via swift-users > wrote: > > Here you go Dmitri. It's an older Dell 1501 that was given to me; I wiped it > and put Ubuntu on it. Th

Re: [swift-users] Conditional generic initializers?

2016-05-15 Thread Karl via swift-users
Yes. You need to put it in an extension. extension Foo where T1 == T2 { convenience init(values: [T1]){ …. } } > On 15 May 2016, at 14:45, Neil Faiman via swift-users > wrote: > > Is it possible for a generic class to have methods (specifically, > initializers) which are only defi