[swift-users] Cannot pass immutable value as inout argument

2018-01-16 Thread Rick Mann via swift-users
Is it not possible for Swift to treat C API const pointers as something that can take let arguments? LGS_EXPORT bool lgs_notify(struct lgs_context_t* ctx, const lgs_notify_params_t* params); . . . let p = lgs_notify_params_t(...) lgs_notify(self.ctx, &p) ^Cannot pass immuta

Re: [swift-users] .apinotesc file placement?

2017-11-29 Thread Rick Mann via swift-users
ation errors illustrates the problem: BLK360API.swift:664:9: Type 'lgs_status_t' has no member 'aborted' BLK360Request.swift:657:9: 'lgs_status_aborted' has been renamed to 'lgs_status_t.aborted' > On Nov 29, 2017, at 16:05 , Rick Mann via swift-users

Re: [swift-users] .apinotesc file placement?

2017-11-29 Thread Rick Mann via swift-users
y of the proper naming conventions or > macros included. I don't really know how to write a robust and complete > module map or apinotes file. > > I'd love to be able to include both of those *outside* of the framework, so > that I don't have to modify their provide

Re: [swift-users] Making a copy of an UnsafePointer

2017-11-15 Thread Rick Mann via swift-users
> On Nov 15, 2017, at 00:48 , Quinn The Eskimo! via swift-users > wrote: > > > On 15 Nov 2017, at 04:16, Rick Mann via swift-users > wrote: > >> Is UnsafeMutablePointer<> not memory managed? > > It is not. Specifically, the code you posted creat

[swift-users] Making a copy of an UnsafePointer

2017-11-14 Thread Rick Mann via swift-users
My code gets some data from an OpenCV cv::Mat object, and passes it to some Swift code that takes it via an UnsafePointer parameter. This works fine until I want to make the call asynchronous (using a DispatchQueue), I think because the underlying cv::Mat gets deallocated by the caller before th

Re: [swift-users] Passing variadic C args through?

2017-11-14 Thread Rick Mann via swift-users
ay straight on as a single argument >>> itself, which means it gets passed as either an NSArray or a pointer (not >>> sure which). Use 'init(format:arguments:)' instead. >>> >>> Jordan >>> >>> >>>> On Nov 14, 2017,

Re: [swift-users] Passing variadic C args through?

2017-11-14 Thread Rick Mann via swift-users
; > Jordan > > >> On Nov 14, 2017, at 17:19, Rick Mann via swift-users >> wrote: >> >> I've had a long-working `debugLog()` method that looks like this: >> >> ``` >> func >> debugLog(_ inMsg: T, file inFile : String = #file, line inLi

[swift-users] Passing variadic C args through?

2017-11-14 Thread Rick Mann via swift-users
I've had a long-working `debugLog()` method that looks like this: ``` func debugLog(_ inMsg: T, file inFile : String = #file, line inLine : Int = #line) { let file = (inFile as NSString).lastPathComponent let s = "\(file):\(inLine)\(inMsg)" print(s) } ``` I wanted to a

Re: [swift-users] Modulo operation in Swift?

2017-11-09 Thread Rick Mann via swift-users
Why is % not available for floating point numbers? > On Nov 9, 2017, at 04:51 , Martin R via swift-users > wrote: > > There was a discussion in swift-evolution, starting at > > > https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160516/018521.html > > about adding a "true modu

Re: [swift-users] .apinotesc file placement?

2017-11-02 Thread Rick Mann via swift-users
a robust and complete module map or apinotes file. I'd love to be able to include both of those *outside* of the framework, so that I don't have to modify their provided items in any way. But for now, I can drop both files into the Framework they provide. Thanks! > > Jordan

[swift-users] .apinotesc file placement?

2017-10-30 Thread Rick Mann via swift-users
I'm using a third-party C library shoehorned into a Framework. It does not have proper ENUM macros nor an apinotes file. I'd like to add one. I'm using Xcode 9. • Can I put the .apinotesc file in the Framework somewhere? • Can I make Xcode automatically compile it? Thanks. -- Rick Mann rm...

Re: [swift-users] Re-initializing lazy vars

2017-10-20 Thread Rick Mann via swift-users
later by adding a consistent syntax for other >> behaviors. I think. I wish I could remember who'd brought up the idea... >> they'd probably know straight away if that's what happened. >> >> - Dave Sweeris >> >>> On Oct 19, 2017, at 5:40 PM

[swift-users] Re-initializing lazy vars

2017-10-19 Thread Rick Mann via swift-users
Googling for the answer, it seemed some versions of Swift supported setting a lazy var property to nil, such that the next time it's accessed, the initializer would be run again. But I just tried this in a playground in Swift 4 and it doesn't work. It sure seems to me like it should work. What'

Re: [swift-users] Swift-C array interop with Swift 4/Xcode 9

2017-09-20 Thread Rick Mann via swift-users
rpreting these results correctly like that. > On Sep 20, 2017, at 17:03 , Rick Mann via swift-users > wrote: > > I've got Swift code wrapping a C API. One of the C structs the API uses looks > like this: > > typedef struct { >size_t size; >floa

[swift-users] Swift-C array interop with Swift 4/Xcode 9

2017-09-20 Thread Rick Mann via swift-users
I've got Swift code wrapping a C API. One of the C structs the API uses looks like this: typedef struct { size_t size; float transformation[16]; float projection[16]; uint32_t width; uint32_t height; } image_info_t; In Swift, the two array members are 16-tuples of floats. Eve

Re: [swift-users] Swift 4 "Cannot use mutating member on immutable value: 'self' is immutable"

2017-09-17 Thread Rick Mann via swift-users
c > algorithms. If I write generic code that uses `popFirst()`, I can only > guarantee the complexity of my code if I can rely on `popFirst()` being O(1). > If someone implements `popFirst()` as O(n), my generic algorithm might go > from O(n^2) to O(n^3), which is quite a c

Re: [swift-users] Swift 4 "Cannot use mutating member on immutable value: 'self' is immutable"

2017-09-15 Thread Rick Mann via swift-users
In my case, it's my own implementation of popFirst(), so I'm not sure why it's complaining at all. Who cares if it's slow? The declaration is identical to popLast(), with the exception that I'm defining mine in an extension that's not Generic (I don't know if you can do it any other way). But ot

Re: [swift-users] Swift 4 "Cannot use mutating member on immutable value: 'self' is immutable"

2017-09-15 Thread Rick Mann via swift-users
>>> On Thu, Sep 14, 2017 at 9:36 AM, Roderick Mann >>> wrote: >>> Yeah, that's not it. I made the change you suggested, I get the same error. >>> >>>> On Sep 13, 2017, at 18:11 , Zhao Xin wrote: >>>> >>>> Change `sel

Re: [swift-users] dynamic requires @objc in Framework, but not in monolithic project

2017-09-13 Thread Rick Mann via swift-users
;> >>> On Sep 13, 2017, at 17:06 , Hooman Mehr wrote: >>> >>> When you create a new project in Xcode 9, the defaults for compiler >>> settings are different. The errors you see are the result of running in >>> full (strict) Swift 4.0 mode which has

[swift-users] Swift 4 "Cannot use mutating member on immutable value: 'self' is immutable"

2017-09-13 Thread Rick Mann via swift-users
Moving to Swift 4, I'm running into an issue for which I can't seem to find an answer in google: "Cannot use mutating member on immutable value: 'self' is immutable" The code looks like: class ModelFetcher : NSObject, URLSessionDelegate { ... static let managerDispatchQueue

[swift-users] dynamic requires @objc in Framework, but not in monolithic project

2017-09-13 Thread Rick Mann via swift-users
I have an iOS app in which I'm factoring out code into a Framework. In Xcode 9 GM (Swift 4), the code builds fine when it's a monolithic app, but some of the files I've pulled into the framework are no longer compiling. One of the errors is: Model.swift:471:14: 'dynamic' var 'dateCreated' must

[swift-users] API notes and modulemap in Frameworks?

2017-09-12 Thread Rick Mann via swift-users
I'm not sure if this is a Swift question, or an Xcode question. When building a Swift-based Framework for distribution to third parties, where do the apinotes and modulemap files go? Thanks. -- Rick Mann rm...@latencyzero.com ___ swift-users mailin

[swift-users] Extracting arbitrary types (e.g. UInt16) out of Data

2017-06-25 Thread Rick Mann via swift-users
I continue to struggle with the "proper" and most efficient way to do things with Data. In this case, I have a set of bytes received over a serial port in a Data. The last two bytes are a (big- or little-endian) UInt16 CRC. However, there maybe an odd or even number of bytes in the Data before

Re: [swift-users] Help! Slicing an array is very expensive

2017-05-10 Thread Rick Mann via swift-users
> On May 10, 2017, at 11:52 , Joe Groff wrote: > > >> On May 8, 2017, at 4:47 PM, Rick Mann via swift-users >> wrote: >> >> I have this C library that interacts with some hardware over the network >> that produces a ton of data. It tells me up front

Re: [swift-users] Making Error sub-enums Equatable

2017-05-10 Thread Rick Mann via swift-users
> On May 10, 2017, at 01:23 , Brent Royal-Gordon wrote: > >> On May 8, 2017, at 2:01 AM, Rick Mann via swift-users >> wrote: >> >> Seriously, I've been googling this for a half-hour, and I can't find an >> answer (everything that comes up is f

[swift-users] Help! Slicing an array is very expensive

2017-05-08 Thread Rick Mann via swift-users
I have this C library that interacts with some hardware over the network that produces a ton of data. It tells me up front the maximum size the data might be so I can allocate a buffer for it, then does a bunch of network requests downloading that data into the buffer, then tells me when it's do

[swift-users] Making Error sub-enums Equatable

2017-05-08 Thread Rick Mann via swift-users
Seriously, I've been googling this for a half-hour, and I can't find an answer (everything that comes up is for ErrorType, absolutely nothing for Error). I have an enum: enum MyErrors : Error { case one(String) case two case three(String) } let a: MyErrors = .one("foo") let b = .two

Re: [swift-users] Annotating C APIs without changing the original header files

2017-05-07 Thread Rick Mann via swift-users
I'm trying to use apinotes for this third-party C library (call it "Lib.dylib"). It has an enum lgs_error_t: typedef enum { lgs_error_none = 0, lgs_error_invalid_handle = -1, lgs_error_null = -2, lgs_error_invalid_parameter = -3, lgs_error_invalid_operation = -4, lgs_error

Re: [swift-users] Slicing a [UInt8] into a Data without copying?

2017-05-04 Thread Rick Mann via swift-users
withUnsafeBytes { buffer in > let d = Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: > buffer.baseAddress!), count: buffer.count, deallocator: .none) > // whatever you do, dont let d escape > } > > > >> On May 4, 2017, at 16:31, Rick Mann via swift-users

[swift-users] Slicing a [UInt8] into a Data without copying?

2017-05-04 Thread Rick Mann via swift-users
Is it possible to make a (immutable) Data() object from a slice of a [UInt8] and avoid copying the data? -- Rick Mann rm...@latencyzero.com ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

Re: [swift-users] Any way to declare a method that suppresses the string interpolation warning?

2017-05-01 Thread Rick Mann via swift-users
te: >>> >>> >>> Saagar Jha >>> >>>> On Apr 21, 2017, at 04:35, Rick Mann via swift-users >>>> wrote: >>>> >>>> I have a debugLog() method that looks like this: >>>> >>>> func >

Re: [swift-users] Why does withUnsafePointer(to:) require a var argument?

2017-04-27 Thread Rick Mann via swift-users
Yeah, okay. So: how do I do this in a way that is safe? -- Rick Mann rm...@latencyzero.com > On Apr 27, 2017, at 23:00, Rien wrote: > > To address your question: > > https://developer.apple.com/reference/foundation/data/1779823-withunsafemutablebytes > > "Warning > The byte pointer argument

Re: [swift-users] Why does withUnsafePointer(to:) require a var argument?

2017-04-27 Thread Rick Mann via swift-users
> On Apr 27, 2017, at 18:56 , Hooman Mehr wrote: > > You should be able to type your `dataBuffer ` as [Int8] (Byte array). Then > you won’t need `withUnsafeMutableBytes`. You can simply call it like this: > > self.request = c_library_call(¶ms, dataBuffer) // Call as if it is a C > array Hmm.

Re: [swift-users] Why does withUnsafePointer(to:) require a var argument?

2017-04-27 Thread Rick Mann via swift-users
gt; array > > It works because of C interoperability compiler magic. > > As long as the instance holding `dataBuffer` is not deallocated and you have > not resized the array, the pointer should remain valid. > >> On Apr 27, 2017, at 4:38 PM, Rick Mann via swift-users >

Re: [swift-users] Why does withUnsafePointer(to:) require a var argument?

2017-04-27 Thread Rick Mann via swift-users
> On Apr 27, 2017, at 01:48 , Alex Blewitt wrote: > ... > The let constant may not even be stored in a single place; if it's known to > be constant it can be in-lined at the point of use and potentially unpacked > and dead code elimination throw away the unused members, for example. > > If y

Re: [swift-users] Why does withUnsafePointer(to:) require a var argument?

2017-04-27 Thread Rick Mann via swift-users
ointer. The languages requires inout arguments to be >> vars, leading to withUnsafePointer() requiring the passed object to be a var. >> >> There may be other subtleties I'm not aware of, though. >> >>> Le 27 avr. 2017 à 02:42, Rick Mann via swift-users >&g

[swift-users] Why does withUnsafePointer(to:) require a var argument?

2017-04-26 Thread Rick Mann via swift-users
We have withUnsafePointer(to:) and withUnsafeMutablePointer(to:). Why does the first take an inout parameter? The function names imply that the first will not modify the pointer (which I take to mean its contents), and it makes it quite clunky to pass in constant things. -- Rick Mann rm...@lat

[swift-users] Any way to enhance C interop "out-of-band?"

2017-04-26 Thread Rick Mann via swift-users
I'm using a third-party C library whose header doesn't properly tag things like enums, and so they show up in Swift without their cases. Is there any way to write an auxiliary file to help the compiler do the conversion (e.g. something in the modulemap file), so that I don't have to modify the d

Re: [swift-users] Still having trouble with C interop (passing buffers)

2017-04-25 Thread Rick Mann via swift-users
ote: > > >> On Apr 25, 2017, at 2:57 PM, Rick Mann via swift-users >> wrote: >> >> I'm trying to pass a Data of allocated size to a C function for it to fill >> in: >> >> >> lib_example_call(_ params: UnsafePointer!, _ data: >> U

[swift-users] Still having trouble with C interop (passing buffers)

2017-04-25 Thread Rick Mann via swift-users
I'm trying to pass a Data of allocated size to a C function for it to fill in: lib_example_call(_ params: UnsafePointer!, _ data: UnsafeMutableRawPointer!) ... { self.dataBuffer = Data(capacity: BufferSizeConstant) var params = lib_call_params_t(); params.data_capacity = BufferSize

Re: [swift-users] withUnsafeMutableBytes is killing me

2017-04-25 Thread Rick Mann via swift-users
> > In your examples, the type checker can't infer the type of ResultType. You'll > have to state it explicitly by specifying the type of the closure's argument. > For example: > > msg.withUnsafeMutableBytes { > (inPointer > : UnsafeMutablePointer > )

[swift-users] withUnsafeMutableBytes is killing me

2017-04-25 Thread Rick Mann via swift-users
The following playground reproduces an issue I'm having, in that the code won't compile depending on the content of the closure. In fact, an empty closure is fine, but when I try to call certain things, it's not. I figure it has something to do with the type inference for inPointer, but I can't

Re: [swift-users] 'inout Data' is not convertible to 'Data'

2017-04-24 Thread Rick Mann via swift-users
Oh wow, it's the debugLog() call! If that's inside the block, it fails to compile. > On Apr 24, 2017, at 14:18 , Rick Mann via swift-users > wrote: > > I could swear this was compiling a couple days ago, as I was making the call > inside the block and dealin

[swift-users] 'inout Data' is not convertible to 'Data'

2017-04-24 Thread Rick Mann via swift-users
I could swear this was compiling a couple days ago, as I was making the call inside the block and dealing with issues around that. Can anyone explain what's going on here? class MyClass { func execute() { self.dataBuffer = Data(capacity: lgsImageDataSize) sel

Re: [swift-users] Any way to declare a method that suppresses the string interpolation warning?

2017-04-23 Thread Rick Mann via swift-users
> On Apr 22, 2017, at 12:23 , Saagar Jha wrote: > > > Saagar Jha > >> On Apr 21, 2017, at 04:35, Rick Mann via swift-users >> wrote: >> >> I have a debugLog() method that looks like this: >> >> func >> debugLog(_ inMsg: T, _ inFile

[swift-users] Any way to declare a method that suppresses the string interpolation warning?

2017-04-21 Thread Rick Mann via swift-users
I have a debugLog() method that looks like this: func debugLog(_ inMsg: T, _ inFile : String = #file, _ inLine : Int = #line) { let df = DateFormatter() df.dateFormat = "-MM-dd HH:mm:ss.SSS" let time = df.string(from: Date()) let file = (inFile as NSStr

[swift-users] Swift version of C #defines

2017-04-21 Thread Rick Mann via swift-users
It seems Swift (in Xcode 8.3.2) can't generate symbols for #defines that have expressions. e.g. this one works, and gets a symbol: #define LGS_MAX_IR_PANORAMA_IMAGE_COUNT 10 But this one doesn't: #define LGS_IMAGE_DATA_SIZE 25*1024*1024 -- Rick Mann rm...@latencyzero.com __

[swift-users] String init from Int8 tuple?

2017-04-18 Thread Rick Mann via swift-users
In my C-interop, I have a need to do this a lot: typedef struct { char message[LGS_MAX_MESSAGE_SIZE]; ...other stuff... } lgs_result_info_t; func callbackFailed(info inInfo: lgs_result_info_t) { var m = inInfo.message // *See note below let message: String = withUnsafePointer

Re: [swift-users] Having a hard time with C interop (callbacks)

2017-04-18 Thread Rick Mann via swift-users
Ah, turns out the passed-in type is UnsafePointer, and I can just call .pointee on that. That seems to have fixed my issues. Not sure if I'm doing the rest of it wrong, but it's not crashing now, at least. > On Apr 18, 2017, at 16:18 , Rick Mann via swift-users > wrote: >

[swift-users] Having a hard time with C interop (callbacks)

2017-04-18 Thread Rick Mann via swift-users
I'm trying to use an API with a complicated callback structure. You pass a struct with a set of pointers to callbacks to a function, along with a pointer to a buffer it fills out. Here's an elided version of the C and Swift code: https://pastebin.com/k3VYJTjB This compiles, but I get a

Re: [swift-users] Importing empty C structs

2017-04-18 Thread Rick Mann via swift-users
> On Apr 18, 2017, at 09:11 , Joe Groff wrote: > > >> On Apr 17, 2017, at 6:19 PM, Rick Mann via swift-users >> wrote: >> >> I'm trying to make a module out of a C library and header file. It has at >> least one empty struct: >>

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

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

[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

[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,

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] 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] 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] 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

[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

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 >> >

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-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 {

[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] 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

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] 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] 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

[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

[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 (

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] 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] 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

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] 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
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] 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
> 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.

[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-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] 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] 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

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
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-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) >>

[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] 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] 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] 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

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

[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] 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

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-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-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)

[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] 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] 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

[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

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

  1   2   >