[swift-users] Why can't Swift instance methods call class methods without qualification?

2016-06-30 Thread Rick Mann via swift-users
Why can my instance methods not call class methods without the class specifier? class MyClass { func foo() { classMethod() } class func classMethod() { } } Why do I have to call MyClass.classMethod()? Just a choice made by the language designers to distinguish

Re: [swift-users] Why can't Swift instance methods call class methods without qualification?

2016-06-30 Thread Rick Mann via swift-users
as curious why it was like this, and if there was a more obvious reason why it needed the qualification. > > Zhaoxin > > On Fri, Jul 1, 2016 at 8:59 AM, Rick Mann via swift-users > wrote: > Why can my instance methods not call class methods without the class > specifier? &

[swift-users] C API returns null but optional thinks it's set anyway

2016-07-01 Thread Rick Mann via swift-users
I have some Swift code (in Xcode 7.3) that's calling a C function in the GDAL library. It's declared like this: typedef void *GDALDatasetH; GDALDatasetH CPL_DLL CPL_STDCALL GDALOpen( const char *pszFilename, GDALAccess eAccess ) CPL_WARN_UNUSED_RESULT; I'm calling it with code like this: class

Re: [swift-users] C API returns null but optional thinks it's set anyway

2016-07-01 Thread Rick Mann via swift-users
ould easily check for Unsafe Pointers with value == 0. > > Dan > > On Fri, Jul 1, 2016 at 2:59 AM, Rick Mann via swift-users > wrote: > I have some Swift code (in Xcode 7.3) that's calling a C function in the GDAL > library. It's declared like this: > > type

Re: [swift-users] Why can't Swift instance methods call class methods without qualification?

2016-07-01 Thread Rick Mann via swift-users
> On Jul 1, 2016, at 10:25 , Nicholas Outram wrote: > > class methods may mutate "mutable static variables” (singletons), which are > dangerous in multi-threaded code. Having the class prefix is a reminder and > therefore requires additional synchronisation if it is to be invoked safely > fro

Re: [swift-users] Why can't Swift instance methods call class methods without qualification?

2016-07-01 Thread Rick Mann via swift-users
> On Jul 1, 2016, at 14:28 , Jens Alfke wrote: > > Sure you can. It’s easy to tell that it calls the instance method, because if > it were calling the class method there would have to be a “Foo.” in front of > it. I'm saying you can't tell what was *intended*, at least, not without knowing a

Re: [swift-users] Why can't Swift instance methods call class methods without qualification?

2016-07-01 Thread Rick Mann via swift-users
> On Jul 1, 2016, at 15:17 , Brent Royal-Gordon wrote: > >> On Jun 30, 2016, at 5:59 PM, Rick Mann via swift-users >> wrote: >> >> Why do I have to call MyClass.classMethod()? Just a choice made by the >> language designers to distinguish the call at th

Re: [swift-users] Why can't Swift instance methods call class methods without qualification?

2016-07-01 Thread Rick Mann via swift-users
> On Jul 1, 2016, at 17:15 , Jens Alfke wrote: > > >> On Jul 1, 2016, at 3:24 PM, Rick Mann via swift-users >> wrote: >> >> Maybe it's just my C++ upbringing > > I think that’s it, yes. (No offense intended.) Different languages have very >

Re: [swift-users] Why can't Swift instance methods call class methods without qualification?

2016-07-03 Thread Rick Mann via swift-users
> Karen Stone wrote: >> I believe there’s real value in being explicit about referencing class >> members. It helps both the reader of the code and it makes writing code >> with typical IDE conveniences like code completion less cluttered and more >> informative. Unfamiliar class methods won’

[swift-users] object.self?

2016-07-08 Thread Rick Mann via swift-users
I just saw a question which brought up something I didn't know about. Apparently sometimes you have to call object.self in a place that looks like you should just use "object." What does this usage mean? for subclassObject in objects { switch subclassObject.self {<--- Here, why not "

Re: [swift-users] object.self?

2016-07-09 Thread Rick Mann via swift-users
gt; statement actually isn't necessary and you should really just be switching on > the value of subclassObject itself, not the value of its type. I would have thought so, but the response to this answer was something along the lines of "I never know when to use the object or

Re: [swift-users] Why there's no Character literals?

2016-07-10 Thread Rick Mann via swift-users
> On Jul 10, 2016, at 11:44 , Saagar Jha via swift-users > wrote: > > Well, what if you wanted to create a String with one character? There’s no > way to differentiate. That hardly seems like the justification. In that case, you'd specify the type: let s: String = '\n' > > > On Jul 7,

[swift-users] Compact iteration of optional collection?

2016-07-28 Thread Rick Mann via swift-users
I often call methods that return an optional collection. I then iterate over it. The problem is, it's a bit cumbersome to write: if let container = someOptionalContainer { for item in container { } } I wish I could just write for item in someOptionalCon

Re: [swift-users] Compact iteration of optional collection?

2016-07-28 Thread Rick Mann via swift-users
array and iterating over it is more expensive than a simple nil check, but that's unlikely to cause issues in practice. Thanks. > On Jul 28, 2016, at 14:56 , Jacob Bandes-Storch wrote: > > How about "for item in someOptionalContainer ?? []" ? > > On Thu, Jul 28, 2

[swift-users] Are value semantics really appropriate in a diagramming app?

2016-08-01 Thread Rick Mann via swift-users
I watched the WWDC 2015 video about protocol-oriented programming and value semantics. Both of them use the example of a diagramming app, where the user can make a diagram of circles and polygons. They make a protocol for Drawable (makes sense), and then make Circle and Polygon structs. I'm wor

Re: [swift-users] Are value semantics really appropriate in a diagramming app?

2016-08-01 Thread Rick Mann via swift-users
> On Aug 1, 2016, at 02:14 , Rimantas Liubertas wrote: > > > Similarly, in the diagramming example from the WWDC videos, how would that > app handle the user editing existing Drawables in the Diagram? Let's say you > allow the user to click on a Drawable and drag it to another location in the

Re: [swift-users] Are value semantics really appropriate in a diagramming app?

2016-08-01 Thread Rick Mann via swift-users
> On Aug 1, 2016, at 02:25 , Rimantas Liubertas wrote: > > > I did. That's one of the two talks I mentioned. > > Well, so they did cover this, didn't they? You move item, you get the new > struct with the new position. And if you save the old one, you have a cheap > way to implement undo. T

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

2016-08-01 Thread Rick Mann via swift-users
In my schematic capture app, I had a class hierarchy that started with Element. From that I derived PartDefinition and PartInstance. Element has an immutable UUID, name, and description. Element knows how to encode itself as XML by conforming to an XMLCoding protocol. Now I'm trying to make Ele

Re: [swift-users] Are value semantics really appropriate in a diagramming app?

2016-08-01 Thread Rick Mann via swift-users
> On Aug 1, 2016, at 16:32 , Jens Alfke wrote: > > >> On Aug 1, 2016, at 1:19 AM, Rick Mann via swift-users >> wrote: >> >> It seems like reference semantics are more appropriate here. > > Yes, they are. (Just because structs exist doesn’t mean y

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

2016-08-01 Thread Rick Mann via swift-users
It sure seems natural. Is there some reason the language can't allow a sub-struct to add member variables, such that the whole is treated like a contiguous set of members? In my case, I have a rect-like value type, but I'd rather it inherit from CGRect, rather than contain a CGRect. That makes

Re: [swift-users] Are value semantics really appropriate in a diagramming app?

2016-08-01 Thread Rick Mann via swift-users
I don't think I get to take advantage of value semantics, and it makes me wonder if any typical, non-trivial model's object graph really has no reference semantics. > > Jack >> On Aug 1, 2016, at 4:32 PM, Jens Alfke via swift-users >> wrote: >> >> &

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

2016-08-02 Thread Rick Mann via swift-users
gt;> } >> } > > Then, if you want to provide a nicer interface, do it with an extension: > >> protocol Element { >> var uuid : UUID{ get } >> var name : String? { get, set } >> } >> >> extension PartInstance : Element { >

Re: [swift-users] Are value semantics really appropriate in a diagramming app?

2016-08-02 Thread Rick Mann via swift-users
> On Aug 2, 2016, at 13:07 , Dave Abrahams via swift-users > wrote: > > > on Mon Aug 01 2016, Rick Mann wrote: > >>> On Aug 1, 2016, at 19:18 , Jack Lawrence wrote: >>> >>> Jens: Why? There are significant benefits to value semantics for >>> this type of problem, for the reasons laid out i

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

2016-08-02 Thread Rick Mann via swift-users
> On Aug 2, 2016, at 07:48 , Karl wrote: > > > >> * 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 someth

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

2016-08-02 Thread Rick Mann via swift-users
I'm trying to define a protocol that has a read-only, immutable member "uuid" that can be set in the init() method, but I'm having trouble. I have this: protocol Element { var uuid : { get } } extension Element { init(...) { self.uuid = ... } } I can't make it let, becau

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

2016-08-02 Thread Rick Mann via swift-users
eeris > >> On Aug 2, 2016, at 6:22 PM, Rick Mann via swift-users >> wrote: >> >> I'm trying to define a protocol that has a read-only, immutable member >> "uuid" that can be set in the init() method, but I'm having trouble. I have >&g

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

2016-08-03 Thread Rick Mann via swift-users
could be disallowed, requiring conforming types to create storage for the property and set it in init()). > > Jordan > > >> On Aug 2, 2016, at 17:01, Rick Mann via swift-users >> wrote: >> >> It complains if I make it a let because computed properties mus

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

2016-08-08 Thread Rick Mann via swift-users
> On Aug 3, 2016, at 03:23 , Dan Loewenherz wrote: > > On Wed, Aug 3, 2016 at 3:51 AM, Rick Mann via swift-users > wrote: > > > On Aug 2, 2016, at 19:06 , Jordan Rose wrote: > > > > I don’t think it makes sense to do this. A protocol cannot control

[swift-users] Swift in bare-metal embedded programming/Swift runtime

2016-08-09 Thread Rick Mann via swift-users
Is it possible to use Swift for bare-metal programming on embedded devices? These devices usually have memory-mapped registers that are read and written to affect the operation of the device. Some can be quite small (e.g. 8-bit registers, simple single physical memory address space), and others

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

2016-08-09 Thread Rick Mann via swift-users
> On Aug 9, 2016, at 08:24 , Karl wrote: > > >> 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 (e

Re: [swift-users] Swift in bare-metal embedded programming/Swift runtime

2016-08-10 Thread Rick Mann via swift-users
> On Aug 10, 2016, at 09:31 , Jens Alfke wrote: > > If you’re going for something bigger than that, why not just use a Raspberry > Pi or C.H.I.P. or one of the other tiny ARM PC boards? They all run Linux, > and I believe people are already working on porting Swift to run on those. > C.H.I.P.

Re: [swift-users] Swift in bare-metal embedded programming/Swift runtime

2016-08-15 Thread Rick Mann via swift-users
list and suggest a "no runtime" >> compiler flag or source code annotation, which disallows anything which >> would use the runtime. I believe there could be advantages outside of >> running on bare-metal, since you could use it to get the compiler to yell at >

[swift-users] protocols, optional, and public

2016-08-26 Thread Rick Mann via swift-users
I'm wrapping CLLocationManager (and its delegate), and I'm trying to create a protocol like this. This is directly cribbed from CLLocationManagerDelegate. --- public protocol LZLocationManagerDelegate : NSObjectProtocol { optional public func locationManager(manager: LZLocationMan

[swift-users] Argument type 'Int' does not conform to expected type 'AnyObject'

2016-09-09 Thread Rick Mann via swift-users
I've seen old (pre-Swift 3) posts online (e.g. http://stackoverflow.com/questions/28920232/why-do-integers-not-conform-to-the-anyobject-protocol) that address this, but my code worked yesterday before I used Xcode 8 GM to migrate it to Swift 3, and now it doesn't, so I'm trying to understand wha

[swift-users] Closure typing changed in Swift 3

2016-09-09 Thread Rick Mann via swift-users
I have some code that implements an HTTP server. You use it like this: server["/some/path"] = { inReq in return .ok(.json(["key" : "value"])) } ".ok" is a case in the HttpResponse enum. The subscript on "server" above looks like this: class HttpServer { typealias Handler = (HttpRequest)

Re: [swift-users] Closure typing changed in Swift 3

2016-09-09 Thread Rick Mann via swift-users
Sep 9, 2016, at 14:34 , Rick Mann via swift-users > wrote: > > I have some code that implements an HTTP server. You use it like this: > > server["/some/path"] = > { inReq in > return .ok(.json(["key" : "value"])) > } > > ".o

[swift-users] Lazy expression is ambiguous?

2016-09-11 Thread Rick Mann via swift-users
I get this error in the following code: "Type of expression is ambiguous without more context", on the DispatchQueue. But only if I mark it as "lazy", and not if I don't. I'm not sure why. class myClass { lazy var myQ = DispatchQueue(label: "Op", attributes: .concurrent)// <-- ERROR

Re: [swift-users] Lazy expression is ambiguous?

2016-09-12 Thread Rick Mann via swift-users
(x: Int, y: Int? = 42) { } > } > > class Foo { > lazy var myQ = Bar(x: 3) > } > > > I'd recommend filing a bug at bugs.swift.org. > > On Sun, Sep 11, 2016 at 10:19 PM, Rick Mann via swift-users > wrote: > I get this error in the following code: &qu

Re: [swift-users] Lazy expression is ambiguous?

2016-09-12 Thread Rick Mann via swift-users
> On Sep 12, 2016, at 00:02 , Quinn The Eskimo! via swift-users > wrote: > > > On 12 Sep 2016, at 06:40, Jacob Bandes-Storch via swift-users > wrote: > >> I'd recommend filing a bug at bugs.swift.org. > > Agreed. Done. https://bugs.swift.org/browse/SR-2616 > Also, you can work around thi

Re: [swift-users] Lazy expression is ambiguous?

2016-09-12 Thread Rick Mann via swift-users
> On Sep 12, 2016, at 00:53 , Quinn The Eskimo! via swift-users > wrote: > > > On 12 Sep 2016, at 08:46, Rick Mann wrote: > >> I had assumed lazy worked like static, which I understand uses dispatch_once >> under the hood. > > Correct. > > [I’m not sure if it actually /uses/ `dispatch_onc

Re: [swift-users] Lazy expression is ambiguous?

2016-09-12 Thread Rick Mann via swift-users
> On Sep 12, 2016, at 03:02 , Quinn The Eskimo! via swift-users > wrote: > > > On 12 Sep 2016, at 09:20, Rick Mann wrote: > >> I've always wondered why that was the case. > > Implementing `dispatch_once` so that it’s fast on all CPU architectures, > including those with a weak memory model

[swift-users] @escaping may only be applied to parameters of function type

2016-09-13 Thread Rick Mann via swift-users
I'm trying to write this function. The errorHandler: parameter is modeled after the NSFileManager enumerate() function. If I include the @escaping you see there, I get the error "@escaping may only be applied to parameters of function type". The second parameter, iterator:, seems to have no pro

Re: [swift-users] @escaping may only be applied to parameters of function type

2016-09-13 Thread Rick Mann via swift-users
It is a short coming in how >> escaping can be applied to things like optional closures. >> >> I was in the process of authoring an email for swift evolution about it and >> haven't yet gotten around to filing a defect about it. >> >> -Shawn >> On Tue

[swift-users] Overload by return type optionality?

2016-10-13 Thread Rick Mann via swift-users
It seems I can write this: extension String { public func deleting(prefix inPrefix: String) -> String public func deleting(prefix inPrefix: String) -> String? } But I was hoping it would do the right thing: let a = s.deleting(prefix: "foo") if let b = s.deleting(prefix: "foo") { } But it fi

Re: [swift-users] Overload by return type optionality?

2016-10-13 Thread Rick Mann via swift-users
> On Oct 13, 2016, at 14:47 , Joe Groff wrote: > > >> On Oct 13, 2016, at 2:36 PM, Rick Mann via swift-users >> wrote: >> >> It seems I can write this: >> >> extension String >> { >> public func deleting(prefix inPrefix: String)

Re: [swift-users] Overload by return type optionality?

2016-10-13 Thread Rick Mann via swift-users
> On Oct 13, 2016, at 14:51 , Greg Parker wrote: > >> >> On Oct 13, 2016, at 2:36 PM, Rick Mann via swift-users >> wrote: >> >> It seems I can write this: >> >> extension String >> { >> public func deleting(prefix inPrefix

[swift-users] Dollar library, good or not?

2016-10-20 Thread Rick Mann via swift-users
A discussion on swift-evolution prompted me to look at the Dollar library (https://github.com/ankurp/Dollar). Is this library an example of good design? It doesn't seem to be to me. No doubt much of the actual functionality is helpful, I'm just asking about the API design. For example, why is e

[swift-users] Implementing += for optional arrays

2016-10-20 Thread Rick Mann via swift-users
When working with URLComponents query items, it would be nice to write code like this: var oqi: [URLQueryItem]? = [..., ..., ...] var comps = URLComponents(…) comps.queryItems += oqi The problem is that queryItems is [URLQueryItem]?, and so I can't just append. I'd like to write a version of +

[swift-users] Why can I not filter or map a dictionary to another dictionary?

2016-10-26 Thread Rick Mann via swift-users
It seems fairly natural to want to do this: let bigDictionary = ... let smallerDictionary = bigDictionary.filter { key, value in } Similarly, it seems natural to want to map this way. Am I overlooking something? -- Rick Mann rm...@latencyzero.com

Re: [swift-users] Why can I not filter or map a dictionary to another dictionary?

2016-10-27 Thread Rick Mann via swift-users
> On Oct 26, 2016, at 22:23 , Dave Abrahams via swift-users > wrote: > > > on Wed Oct 26 2016, Rick Mann wrote: > >> It seems fairly natural to want to do this: >> >> let bigDictionary = ... >> let smallerDictionary = bigDictionary.filter { key, value in > returning Bool> } > >> Similarly,

Re: [swift-users] Why can I not filter or map a dictionary to another dictionary?

2016-10-27 Thread Rick Mann via swift-users
xample, sd is an array of tuples of (key, value), not a dictionary. > >On 27/10/2016, 01:12, "Rick Mann via swift-users" > wrote: > >It seems fairly natural to want to do this: > >let bigDictionary = ... >let smallerDictionary = bigD

Re: [swift-users] Why can I not filter or map a dictionary to another dictionary?

2016-10-31 Thread Rick Mann via swift-users
> On Oct 27, 2016, at 10:29 , Dave Abrahams wrote: > > > on Thu Oct 27 2016, Rick Mann wrote: > >>> On Oct 26, 2016, at 22:23 , Dave Abrahams via swift-users >>> wrote: >>> >>> >>> on Wed Oct 26 2016, Rick Mann wrote: >>> >> It seems fairly natural to want to do this: l

[swift-users] Thinking in Swift: Click handling

2016-11-10 Thread Rick Mann via swift-users
I'm still just learning Swift, after decades of C++ and Objective-C(++). I've written entire apps in Swift, but I don't "think in Swift" very well yet. So I'm looking for advice on what classes, protocols, and extensions might be "swifty" in this example. Background -- I'm working on a

[swift-users] Misleading? cannot subscript a value of type 'inout [PathPoint]' with optional field

2016-11-11 Thread Rick Mann via swift-users
I think the error I'm getting here is misleading. Should I file a bug? import CoreGraphics func +=(inLHS : inout CGPoint, inRHS : CGPoint) { inLHS.x += inRHS.x inLHS.y += inRHS.y } struct PathPoint { varanchorPt:CGPoint? } var points = [PathPoint()] let dv = CGPoint(x: 0, y

Re: [swift-users] Misleading? cannot subscript a value of type 'inout [PathPoint]' with optional field

2016-11-11 Thread Rick Mann via swift-users
out CGPoint' > points[0].anchorPt += dv > ~~^~~~ > > but that's still not great. So, yes, please do file a bug at bugs.swift.org. > > Thank you! > Jordan > >> On Nov 11, 2016, at 13:29, Rick Mann via swift-users >> wrote: >> &g

[swift-users] Reflection in Swift 3?

2016-11-12 Thread Rick Mann via swift-users
So, it seems there's still no way to do something like instantiate a class given only its name (as a String)? In my situation, I have a number of subclasses (or protocol implementations), which parallel some other class hierarchy. I need to dynamically create one based on the name of another. I

Re: [swift-users] Reflection in Swift 3?

2016-11-12 Thread Rick Mann via swift-users
> On Nov 12, 2016, at 22:47 , David Sweeris wrote: > > >> On Nov 13, 2016, at 00:38, Rick Mann via swift-users >> wrote: >> >> So, it seems there's still no way to do something like instantiate a class >> given only its name (as a String)

Re: [swift-users] Reflection in Swift 3?

2016-11-14 Thread Rick Mann via swift-users
upported optional methods without @objc (I guess it's not that big a deal to use @objc). > On Nov 13, 2016, at 11:19 , David Sweeris wrote: > > >> On Nov 13, 2016, at 1:55 AM, Rick Mann wrote: >> >> >>> On Nov 12, 2016, at 22:47 , David Sweeris wrote: &

Re: [swift-users] Reflection in Swift 3?

2016-11-15 Thread Rick Mann via swift-users
> if you don’t know what’s in the string, you need to validate it (imagine if > the user of your app finds out that they can cause you to instantiate any > arbitrary class) and if you do know what’s in the string, why are you not > creating the instance directly? > > >>

Re: [swift-users] Reflection in Swift 3?

2016-11-15 Thread Rick Mann via swift-users
o validate it >>> (imagine if the user of your app finds out that they can cause you to >>> instantiate any arbitrary class) and if you do know what’s in the string, >>> why are you not creating the instance directly? >>> >>> >>>> On 14 Nov

[swift-users] Attempting to call default protocol implementation crashes Playground

2016-11-15 Thread Rick Mann via swift-users
The following gives Xcode 8.1 a very hard time. Eventually I get a Bad Access on the last line. I'm guessing it's a recursive call. Is there any way to call the default implementation from a "real" implementation? protocol FooPro { func fooFunc() } extension FooPro { func

Re: [swift-users] Attempting to call default protocol implementation crashes Playground

2016-11-15 Thread Rick Mann via swift-users
;) > } > } > > let fc = FooClass() > fc.fooFunc() > > Dan > > On Tue, Nov 15, 2016 at 4:28 PM, Rick Mann via swift-users > wrote: > The following gives Xcode 8.1 a very hard time. Eventually I get a Bad Access > on the last line. I'm gu

Re: [swift-users] Attempting to call default protocol implementation crashes Playground

2016-11-15 Thread Rick Mann via swift-users
consider it like something super class does. If you want it that > way, use class inheritance instead. > > Zhaoxin > > Get Outlook for iOS > > _____ > From: Rick Mann via swift-users > Sent: 星期三, 十一月 16, 2016 07:51 > Subject: Re: [s

[swift-users] Implementing signum

2016-11-19 Thread Rick Mann via swift-users
I'm trying to do this: protocol Signumable { func sgn() -> Self } extension Signumable { func sgn() -> Self { let pos = 0 < self // Error let neg = self < 0 // Error let p =

Re: [swift-users] Implementing signum

2016-11-20 Thread Rick Mann via swift-users
existing `SignedNumber` > protocol instead of introducing your own `Signumable`, unless if you need to > write other generic algorithms that need your protocol as their constraints. > >> On Nov 19, 2016, at 6:44 PM, Rick Mann via swift-users >> wrote: >> >

[swift-users] Bool to Int

2016-11-20 Thread Rick Mann via swift-users
It seems I can't do this: let r = Int(a > b) but I can do it with a literal: let r = Int(true) I'd like to do this to implement signum without branching, but perhaps that's not possible. -- Rick Mann rm...@latencyzero.com ___ swift-users mailing

Re: [swift-users] Bool to Int

2016-11-20 Thread Rick Mann via swift-users
'm doing what I need with branching, but it would be nice to find a more efficient way. > > > Jon > >> On Nov 20, 2016, at 10:48 PM, Rick Mann via swift-users >> wrote: >> >> It seems I can't do this: >> >> let r = Int(a > b) >>

Re: [swift-users] Bool to Int

2016-11-21 Thread Rick Mann via swift-users
I'll try profiling it (or looking at the generated assembly). Thanks! > On Nov 20, 2016, at 21:15 , Marco S Hyman wrote: > >> Is there a way that avoids branching? > > Don’t know. Have you profiled > > let r = a > b ? 1 : 0 > > to know it is an issue? >> >> So, according to Xcode, "true" a

Re: [swift-users] Bool to Int

2016-11-21 Thread Rick Mann via swift-users
> On Nov 21, 2016, at 09:46 , Kenny Leung via swift-users > wrote: > > This is so confusing. "Literals are untyped", but there’s a “BooleanLiteral”, > which is obviously of type Boolean. Agreed. -- Rick Mann rm...@latencyzero.com ___ swift-users

Re: [swift-users] Bool to Int

2016-11-21 Thread Rick Mann via swift-users
> On Nov 21, 2016, at 15:09 , Marco S Hyman wrote: > >> Except it does, because if I write >> >> let a = 2 > >> a is of type Int (at least, according to Xcode's code completion). > > and if you write > > let b = 2 + 0.5 > > 2 is treated as a double. The type of the literal “2” va

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

2016-11-21 Thread Rick Mann via swift-users
My googling is not turning up an answer that works in Xcode 8.1. I'd like to do this: import Accelerate extension Array where Element == Double { func sum() -> Double { var result: Double = 0.0 vDSP_sveD(self, 1, &r

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

2016-11-21 Thread Rick Mann via swift-users
DSP_Length(array.count)) } > return result > } > > func sum(_ array: ArraySlice) -> Float { > var result = Float() > array.withUnsafeBufferPointer { vDSP_sve($0.baseAddress!, 1, &result, > vDSP_Length(array.count)) } > return result > } > > The

[swift-users] Any equivalent to Java's AtomicInteger?

2016-11-21 Thread Rick Mann via swift-users
A lot of architectures provide CPU support for atomic increment and the like. does, too, but most of it is unavailable in Xcode 8.1. Is there a Swift AtomicInteger? Is that worth adding to the language? -- Rick Mann rm...@latencyzero.com ___ swift-

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

2016-11-22 Thread Rick Mann via swift-users
> On Nov 22, 2016, at 03:04 , Tino Heth <2...@gmx.de> wrote: > > Hi Rick, > > as evolution is somewhat paused, swift-users seems to gain more traction ;-) > > Imho the most natural would be > extension Array { > … > } > > I hope to see this addition included when the topic is discussed again.

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

2016-11-22 Thread Rick Mann via swift-users
> > > > -- > Adrian Zubarev > Sent with Airmail > > Am 22. November 2016 um 01:32:42, Rick Mann via swift-users > (swift-users@swift.org) schrieb: > >> My googling is not turning up an answer that works in Xcode 8.1. I'd like to >> do this: >

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

2016-11-22 Thread Rick Mann via swift-users
ength(array.count)) } >>> return result >>> } >>> >>> func sum(_ array: Array) -> Float { >>> var result = Float() >>> vDSP_sve(array, 1, &result, vDSP_Length(array.count)) >>> return result >>> } >>>

Re: [swift-users] Any equivalent to Java's AtomicInteger?

2016-11-22 Thread Rick Mann via swift-users
aps the compiler magically optimizes this down to an atomic instruction, but I doubt it. BTW, is there any easy way to see the generated assembly? Seems to be a missing feature in Xcode. > >> On Nov 21, 2016, at 7:55 PM, Rick Mann via swift-users >> wrote: >> >>

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

2016-11-22 Thread Rick Mann via swift-users
in sequence { result += element } >>>>> return result >>>>> } >>>>> >>>>> func sum(_ array: Array) -> Double { >>>>> var result = Double() >>>>> vDSP_sveD(array, 1, &result, vDSP_Length(array.coun

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

2016-11-22 Thread Rick Mann via swift-users
nctions gives you the most >>>>>>> coverage and best performance, at the expense of repetition and >>>>>>> boilerplate code: >>>>>>> >>>>>>> func sum(_ sequence: S) -> S.Iterator.Elemen

[swift-users] Decimal to Double?

2016-11-28 Thread Rick Mann via swift-users
How do I get a Double from a Decimal? TIA, -- Rick Mann rm...@latencyzero.com ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

Re: [swift-users] Decimal to Double?

2016-11-28 Thread Rick Mann via swift-users
Ugh. Thanks! > On Nov 28, 2016, at 02:40 , Alex Blewitt wrote: > > You can wrap it with an NSDecimalNumber, and then cast it to a Double from > there: > > Double(NSDecimalNumber(decimal:Decimal(1.0))) > > Alex > >> On 28 Nov 2016, at 10:13, Rick Mann via s

[swift-users] Dimensional analysis

2016-11-28 Thread Rick Mann via swift-users
My earlier post about converting Decimal to Double was part of a larger effort by me to write a calculator app that supports dimensional analysis/unit conversions. I've explored some existing libraries on the topic, ranging from this one in Common Lisp (

[swift-users] Changing precedence of / operator for my protocol?

2016-11-29 Thread Rick Mann via swift-users
Working on dimensional analysis, I have some proof-of-concept code that seems to be working: let n1 = kilogram * meter / second * second ([(kg⋅m) / s]⋅s) let n2 = kilogram * meter / (second * second) [(kg⋅m) / (s⋅s)] Note: () around unit products, [] around unit quotients. I'd

Re: [swift-users] Changing precedence of / operator for my protocol?

2016-11-29 Thread Rick Mann via swift-users
gt; On 30 November 2016 at 09:28, Greg Parker via swift-users > wrote: > > > On Nov 29, 2016, at 2:55 AM, Rick Mann via swift-users > > wrote: > > > > Working on dimensional analysis, I have some proof-of-concept code that > > seems to be working: > > &g

Re: [swift-users] Changing precedence of / operator for my protocol?

2016-11-29 Thread Rick Mann via swift-users
as they are. No need to add > confusion; it works to use parentheses. > > > > > -- Howard. > > > > On 30 November 2016 at 09:28, Greg Parker via swift-users > > wrote: > > > > > On Nov 29, 2016, at 2:55 AM, Rick Mann via swift-users >

Re: [swift-users] Dimensional analysis

2016-12-04 Thread Rick Mann via swift-users
> On Dec 1, 2016, at 11:36 , Dave Abrahams via swift-users > wrote: > > > on Mon Nov 28 2016, Rick Mann wrote: > >> My earlier post about converting Decimal to Double was part of a >> larger effort by me to write a calculator app that supports >> dimensional analysis/unit conversions. I've e

Re: [swift-users] ANTLR 4.6 now generates parsers in Swift

2016-12-15 Thread Rick Mann via swift-users
Awesome! > On Dec 15, 2016, at 22:11 , Terence Parr via swift-users > wrote: > > Dear Swift-users! Just a quick note that I finally got the Swift code > generation target for the ANTLR 4 parser generator integrated and released! > You can see the release notes here: > > https://github.com/a

[swift-users] for with optional collection?

2017-02-09 Thread Rick Mann via swift-users
Is there any concise way to write the following? if let collection = someOptionalCollection { for item in collection { } } I can imagine more complicated things, too: if let collection = someOptionalCollection as? [SomeType] { for item in collection { } } It would be nic

Re: [swift-users] for with optional collection?

2017-02-09 Thread Rick Mann via swift-users
> On Feb 9, 2017, at 13:31 , Saagar Jha wrote: > > for item in someOptionalCollection ?? [] { > item.doSomething() > } > Thanks, this is probably the closest. Sadly I can't seem to test downcasting because Playgrounds just stop working, with no feedback, for this code: class Foo {

Re: [swift-users] for with optional collection?

2017-02-10 Thread Rick Mann via swift-users
I love the idea of for in? (Or even for? In). You should pitch that to evolution. Sent from my iPhone > On Feb 10, 2017, at 07:04, Tino Heth <2...@gmx.de> wrote: > > >> Is there any concise way to write the following? >> >> if let collection = someOptionalCollection >> { >>for item in co

Re: [swift-users] for with optional collection?

2017-02-10 Thread Rick Mann via swift-users
o parallel "for > case let x? in array { }" > > >> On Fri, Feb 10, 2017 at 1:03 PM, Rick Mann via swift-users >> wrote: >> I love the idea of for in? (Or even for? In). You should pitch that to >> evolution. >> >> Sent from my iPhone >> >

[swift-users] Swift linux repl can't import

2017-04-04 Thread Rick Mann via swift-users
The installation instructions for Swift on Linux imply that the tarball can be extracted anywhere, and the PATH set, and all should be well. But unfortunately, while that's partly true, when I try to import packages, it fails (Ubuntu 16.04 on Parallels on macOS 10.12.3): $ swift Welcome to Swif

[swift-users] Linux equivalent of macOS/iOS run loop, aka libdispatch/Dispatch on Linux

2017-04-05 Thread Rick Mann via swift-users
I've got Swift and libdispatch installed and linking under Ubuntu 16.04, but I'm not sure how to set up the Linux equivalent of the macOS run loop in order to service all the dispatch queues. I'm having a hard time finding an example of how to do this. Some GCD C code calls dispatch_main() from

Re: [swift-users] Linux equivalent of macOS/iOS run loop, aka libdispatch/Dispatch on Linux

2017-04-05 Thread Rick Mann via swift-users
nding it. I finally found a Swift example that used dispatch_main(), and the Swift compiler helpfully told me to try dispatchMain(). Thank you for confirming! > > > > Jon > >> On Apr 5, 2017, at 4:28 PM, Rick Mann via swift-users >> wrote: >> >> I

[swift-users] Cannot subclass a class with objc_subclassing_restricted attribute

2017-04-14 Thread Rick Mann via swift-users
I'm refactoring some Objective-C code to inherit from a new Swift super class. This has been going okay, and I've been cleaning up build errors as I spot them (some auxiliary enums caused enum name changes, etc.). But my last error seems to be that I can't subclass the Swift class: "Cannot subc

Re: [swift-users] Cannot subclass a class with objc_subclassing_restricted attribute

2017-04-17 Thread Rick Mann via swift-users
> On Apr 14, 2017, at 22:33 , Guillaume Lessard > wrote: > > Your class probably needs to be declared as open. > > @objc open class Camera : NSObject {} Thanks. Sadly, that does not fix it. > Guillaume Lessard > >> On Apr 14, 2017, at 20:41, Rick M

[swift-users] Importing empty C structs

2017-04-17 Thread Rick Mann via swift-users
I'm trying to make a module out of a C library and header file. It has at least one empty struct: struct lgs_context_t {}; and a function: LGS_EXPORT struct lgs_context_t* lgs_init(const lgs_context_params_t* params); Swift sees the function, I can call it and assign the result to a variable,

[swift-users] Can't access Swift class from Objective-C

2017-04-17 Thread Rick Mann via swift-users
My Objective-C file is importing "Module-Swift.h", and that file has some of my other Swift classes, but not the one I just wrote. I've tried making the class public, but I didn't need to do that on any of the others. I've tried cleaning the build folder of my Xcode project, but I get the same

Re: [swift-users] Cannot subclass a class with objc_subclassing_restricted attribute

2017-04-17 Thread Rick Mann via swift-users
> On Apr 17, 2017, at 08:54 , Joe Groff wrote: > > >> On Apr 14, 2017, at 7:41 PM, Rick Mann via swift-users >> wrote: >> >> I'm refactoring some Objective-C code to inherit from a new Swift super >> class. This has been going okay, and I've

Re: [swift-users] Can't access Swift class from Objective-C

2017-04-18 Thread Rick Mann via swift-users
c. (There's an implementation reason for this; > it's not just the compiler being capricious.) > - In frameworks, only public and open classes are included in the generated > header, since it's part of your framework's public interface. > > Are you in any of these si

  1   2   >