Re: [swift-users] appending packed bytes to [UInt8]

2018-01-10 Thread Jens Persson via swift-users
I'm not sure what you mean by "I need the buffer to be a vector /.../" but perhaps this may be of some help: struct S { var x: Float var y: Float var z: Float var r: UInt8 var g: UInt8 var b: UInt8 var a: UInt8 } var buf = S(x: 0.1, y: 1.2, z: 2.3, r: 11, g: 22, b: 33,

Re: [swift-users] Tuple of two or more instances to withExtendedLifetime

2017-12-13 Thread Jens Persson via swift-users
ntended, but I'd like to get someone more versed in SIL than me to > verify that. Andy? > > > > Jordan > > > > > >> On Dec 13, 2017, at 01:28, Jens Persson via swift-users < > swift-users@swift.org> wrote: > >> > >> There are no restric

[swift-users] Tuple of two or more instances to withExtendedLifetime

2017-12-13 Thread Jens Persson via swift-users
There are no restrictions on the type of the first argument to withExtendedLiftetime, even though it makes sense only for reference types. So both the below variants will compile, and my question is if the first one will work as expected (extending the lifetime of both a and b) or if the second

Re: [swift-users] abs() Bug?

2017-12-12 Thread Jens Persson via swift-users
They all crash when I test it with Xcode 9.2 (default toolchain and dev snapshot 2017-12-09, command line app), in what environment are you seeing the non-crashing behavior? My guess is that all of them crashing is the intended behavior, since the operations result in an overflow.. /Jens On

Re: [swift-users] Swift's method dispatch

2017-12-11 Thread Jens Persson via swift-users
table which obviously can’t use a default implementation which requires T > to be Int. > > > /Jens > > On Sun, Dec 10, 2017 at 11:30 PM, Jens Persson via swift-users < > swift-users@swift.org> wrote: > >> Thank you Matthew, I will try to digest and incorpor

Re: [swift-users] Faktura 469782890

2017-12-11 Thread Jens Persson via swift-users
Oops, sorry (my mail client unfortunately happens to autocomplete my own mail to "jens via swift-users"). ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

Re: [swift-users] Faktura 469782890

2017-12-11 Thread Jens Persson via swift-users
bet 12/12 2017-12-01 7:04 GMT+01:00 Loopia Faktura : > > Ny faktura från Loopia > > Fakturan ligger bifogad som PDF i detta meddelande och finns även > tillgänglig i Loopia Kundzon under > "Fakturor". Vi behöver din betalning *senast 31

Re: [swift-users] Swift's method dispatch

2017-12-10 Thread Jens Persson via swift-users
Oh btw Matthew, you wouldn't consider https://bugs.swift.org/browse/SR-6564 a bug then? /Jens On Sun, Dec 10, 2017 at 11:30 PM, Jens Persson via swift-users < swift-users@swift.org> wrote: > Thank you Matthew, I will try to digest and incorporate your explanation. > > I'm

[swift-users] Swift's method dispatch

2017-12-08 Thread Jens Persson via swift-users
Hi all! Can someone please explain the rationale behind the last line printing "T is unknown" rather than (what I would expect): "T is Int" in the following program? protocol P { associatedtype T func f() // * } extension P { func f() { print("T is unknown") } } extension P where T

Re: [swift-users] Why no unsafeRemainder(dividingBy: Self) in FixedWidthInteger?

2017-12-05 Thread Jens Persson via swift-users
s: func remainderReportingOverflow(dividingBy: Self) but there is no: func unsafeRemainder(dividingBy: Self) 2. Does anyone know a better way to implement the &%% above (to be as fast as possible)? /Jens On Sun, Oct 29, 2017 at 9:13 AM, Jens Persson via swift-users < swift-users@swift.org> wrot

Re: [swift-users] FloatingPoint/BinaryFloatingPoint protocol and concrete FloatingPoint types

2017-12-03 Thread Jens Persson via swift-users
unc someComplexCalculation(input: T) -> T { let input80 = input.float80 let output80 = maxPrecisionCalculation(input: input80) return T(output80) } /Jens On Fri, Dec 1, 2017 at 11:59 PM, David Sweeris <daveswee...@mac.com> wrote: > > > On Dec 1, 2017, at 13:18, Jens Pe

Re: [swift-users] FloatingPoint/BinaryFloatingPoint protocol and concrete FloatingPoint types

2017-12-01 Thread Jens Persson via swift-users
protocol Float80Convertible : BinaryFloatingPoint { init(_ value: Float80) var float80: Float80 { get } } extension Double : Float80Convertible { var float80: Float80 { return Float80(self) } } extension Float : Float80Convertible { var float80: Float80 { return Float80(self) } }

[swift-users] Modulo operation in Swift?

2017-11-09 Thread Jens Persson via swift-users
Hi all! Is there a modulo operation/function in Swift? I want the "true" mathematical modulo (as % in Python), and not remainder (as % in Swift). Do I have to implement this basic mathematical function myself and if so what is the best way to write it (it will be heavily used so I want it to be

Re: [swift-users] Using eg @_specialize in apps submitted to the AppStore?

2017-11-02 Thread Jens Persson via swift-users
doesn't compile any more. ;-) > > (Good question, worth asking.) > > Jordan > > > > On Nov 1, 2017, at 02:33, Jens Persson via swift-users < > swift-users@swift.org> wrote: > > > > Hi! > > > > Is it OK to use internal a

[swift-users] Using eg @_specialize in apps submitted to the AppStore?

2017-11-01 Thread Jens Persson via swift-users
Hi! Is it OK to use internal attributes such as @_specialize in apps submitted to the App Store? /Jens ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

[swift-users] Why no unsafeRemainder(dividingBy: Self) in FixedWidthInteger?

2017-10-29 Thread Jens Persson via swift-users
I have some integer processing code that is called very intensively and need to be as fast as possible, I therefore use &+ &- &/ &* instead of + - / * which results in a significant speedup. However, I also need to use % and I noticed that there is no &% ... That is, FixedWidthInteger has: func

Re: [swift-users] Why no new Development Snapshots since Aug 3?

2017-08-16 Thread Jens Persson via swift-users
ilds/development/xcode/ > swift-DEVELOPMENT-SNAPSHOT-2017-08-15-a/swift- > DEVELOPMENT-SNAPSHOT-2017-08-15-a-osx.pkg on this server. > > (I could download 2017-08-14 yesterday though.) > /Jens > > On Fri, Aug 11, 2017 at 9:55 PM, Jens Persson via swift-users < > swift-users

Re: [swift-users] Why no new Development Snapshots since Aug 3?

2017-08-15 Thread Jens Persson via swift-users
-15-a/swift-DEVELOPMENT-SNAPSHOT-2017-08-15-a-osx.pkg on this server. (I could download 2017-08-14 yesterday though.) /Jens On Fri, Aug 11, 2017 at 9:55 PM, Jens Persson via swift-users < swift-users@swift.org> wrote: > Ok, thanks! > /Jens > > On Fri, Aug 11, 2017 at 5:39 AM, Mis

Re: [swift-users] Why no new Development Snapshots since Aug 3?

2017-08-11 Thread Jens Persson via swift-users
job/oss-lldb-incremental-osx/ > https://ci.swift.org/job/oss-lldb-incremental-linux-ubuntu-16_04/ > https://ci.swift.org/job/oss-lldb-incremental-linux-ubuntu-16_10/ > > Thanks, > Mishal Shah > > On Aug 10, 2017, at 6:42 PM, Jens Persson via swift-users < > swift-user

[swift-users] Why no new Development Snapshots since Aug 3?

2017-08-10 Thread Jens Persson via swift-users
The most recent Development Snapshot is 2017-08-03, but it used to be a new one almost daily. What happened? /Jens ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

[swift-users] Convenience initializers in structs?

2017-07-18 Thread Jens Persson via swift-users
Start a command line project in Xcode 9 beta 3 and copy paste this single line of code into main.swift let _ = UInt8.init(extendingOrTruncating: UInt64(123456)) Now look at Quick Help while placing the cursor on `init` and then on `extendingOrTruncating`. Note that (and how) the documentation

[swift-users] Recommended way to write conditional compilation for 32- or 64-bit?

2017-07-16 Thread Jens Persson via swift-users
I need to define some datatypes differently depending on if the target is 32- or 64-bit. The code should compile on any 32- or 64-bit platform. Is the following the recommended way to do this? #if arch(x86_64) || arch(arm64) // Define the types, knowing that we're on a 64-bit platform.

Re: [swift-users] komihåg swift 4 Vector

2017-07-10 Thread Jens Persson via swift-users
Oops sorry, I intended to send that code to myself but autocompletion made it go to swift-users ... /Jens On Mon, Jul 10, 2017 at 7:46 PM, Jens Persson via swift-users < swift-users@swift.org> wrote: > protocol VectorStorage { > associatedtype A > associatedtype B >

Re: [swift-users] is this a defect in equatable for swift tuples?

2017-07-09 Thread Jens Persson via swift-users
Since Array has .elementsEqual, another workaround (until conditional conformance) is: class Tree : Equatable { let rootData:Int let children:[(String, Tree)] init(rootData: Int, children: [(String, Tree)]) { self.rootData = rootData self.children = children }

Re: [swift-users] is this a defect in equatable for swift tuples?

2017-07-09 Thread Jens Persson via swift-users
(Also, note that your implementation of == uses lhs === rhs thus will only return true when lhs and rhs are the same instance of SomeClass.) /Jens On Sun, Jul 9, 2017 at 5:24 PM, Jens Persson wrote: > Making SomeClass conform to Equatable should fix it: > > class SomeClass :

Re: [swift-users] is this a defect in equatable for swift tuples?

2017-07-09 Thread Jens Persson via swift-users
Making SomeClass conform to Equatable should fix it: class SomeClass : Equatable { static public func ==(_ lhs:SomeClass, _ rhs:SomeClass) -> Bool { return lhs === rhs } } /Jens On Sun, Jul 9, 2017 at 5:11 PM, David Baraff via swift-users < swift-users@swift.org> wrote: >

Re: [swift-users] How to add this generic static func as a protocol requirement?

2017-07-07 Thread Jens Persson via swift-users
R > } > > Slava > > > On Jul 7, 2017, at 1:50 AM, Jens Persson via swift-users < > swift-users@swift.org> wrote: > > > > protocol P { > > // … > > // For example the following will not work: > > // static func foo<T, R>(_ v:

[swift-users] How to add this generic static func as a protocol requirement?

2017-07-07 Thread Jens Persson via swift-users
protocol P { // … // For example the following will not work: // static func foo(_ v: T) -> R // Is there some other way? // … } struct S2 : P { static func foo(_ v: T) -> (T, T) { return (v, v) } } struct S3 : P { static func foo(_ v: T) -> (T, T, T)

Re: [swift-users] Design guidelines for computed property vs no-arg method

2017-07-05 Thread Jens Persson via swift-users
On Wed, Jul 5, 2017 at 11:50 PM, Dave Abrahams via swift-users < swift-users@swift.org> wrote: > … > As a name, signum falls into the “term-of-art” category, so at least > that part is in conformance to the guidelines. In specialized areas > like this one, I generally defer to the domain

[swift-users] Design guidelines for computed property vs no-arg method

2017-07-05 Thread Jens Persson via swift-users
Why is eg the BinaryInteger.signum() a method and not a computed property? public protocol BinaryInteger … { /// Returns `-1` if this value is negative and `1` if it's positive; /// otherwise, `0`. /// /// - Returns: The sign of this number, expressed as an integer of the same

Re: [swift-users] Disable "indexing while building" in Xcode9 (unknown argument: `-index-store-path`)

2017-07-05 Thread Jens Persson via swift-users
I'm using Xcode 9 beta 2 (on Sierra 10.12.5) and my top 3 annoyances are: 1. Having to manually scroll the text editor sideways to follow the caret/cursor as it moves out of view (!) while editing a line that is wider than the text editor. 2. Non-working "File -> Add Files" (Options: Copy items

Re: [swift-users] [swift-evolution] Request for information about constrained protocol inheritance

2017-07-05 Thread Jens Persson via swift-users
Ah, thanks! Do you happen to know of any particular std lib protocol of the form: protocol P : OtherP where OtherP.AT ... ? On Wed, Jul 5, 2017 at 7:53 AM, Xiaodi Wu wrote: > Replying to swift-users as well, as it's probably the more appropriate > forum. > > SE-0142 (Permit

Re: [swift-users] Intended behavior or bug in Dictionary's new subscript(_:default:)?

2017-06-18 Thread Jens Persson via swift-users
the set. > There’s downsides to this though: you would no longer be able to use this > defaulting subscript with immutable dictionaries, and getting a default > value would add it which might be very unexpected. > > > On Jun 16, 2017, at 1:40 PM, Jens Persson via swift-users &l

[swift-users] Intended behavior or bug in Dictionary's new subscript(_:default:)?

2017-06-16 Thread Jens Persson via swift-users
// Swift 4, Xcode 9 beta 1, default toolchain import Foundation var d1 = [Int : String]() d1[1, default: .init()].append("a") d1[2, default: .init()].append("b") d1[3, default: .init()].append("c") d1[1, default: .init()].append("d") print(d1) // [2: "b", 3: "c", 1: "ad"] as expected. var d2 =

[swift-users] How to rewrite this code using improved numeric protocols of Swift 4

2017-06-16 Thread Jens Persson via swift-users
I've made an unsuccessful attempt to rewrite the below code in a shorter, more generic way using the improved numeric protocols in Swift 4 (BinaryFloatingPoint, FixedWidthInteger et al). So now I'm wondering if anyone would like to give it a try (or declare that it is not possible). The following

Re: [swift-users] Recommended way to collect elements into collection-valued Dictionary?

2017-06-16 Thread Jens Persson via swift-users
mutating func append(value: Value.Element, for key: Key) { > self[key, default: Value()].append(value) > } > } > > > > > On Jun 15, 2017, at 3:12 PM, Jens Persson via swift-users < > swift-users@swift.org > <javascript:_e(%7B%7D,'cvml','swift-

[swift-users] Recommended way to collect elements into collection-valued Dictionary?

2017-06-15 Thread Jens Persson via swift-users
let question = """ Please see the extension to Dictionary below. Is there a simpler or better way to accomplish the same thing? """ extension Dictionary where Value: RangeReplaceableCollection, Value: ExpressibleByArrayLiteral, Value.Element == Value.ArrayLiteralElement {

Re: [swift-users] Runtime crash caused by (NS)CharacterSet.hasMember?

2017-06-13 Thread Jens Persson via swift-users
Filed 32748795 On Tue, Jun 13, 2017 at 10:55 PM, David Hart <da...@hartbit.com> wrote: > Worth a radar to improve docs. > > On 13 Jun 2017, at 22:12, Jens Persson via swift-users < > swift-users@swift.org> wrote: > > Thanks! > > The documentation tha

Re: [swift-users] Runtime crash caused by (NS)CharacterSet.hasMember?

2017-06-13 Thread Jens Persson via swift-users
s more robust, Apple is > definitely saying Don’t Do That. > > Doug Hill > https://github.com/djfitz/SFFontFeatures > > > On Jun 13, 2017, at 9:42 AM, Jens Persson via swift-users < > swift-users@swift.org> wrote: > > PS > There are only 17 planes in the (cur

Re: [swift-users] Runtime crash caused by (NS)CharacterSet.hasMember?

2017-06-13 Thread Jens Persson via swift-users
PS There are only 17 planes in the (current?) Unicode standard, but I'm assuming that the CharacterSet.hasMember(inPlane:) shouldn't (randomly?) crash for UInt8 values other than 0 ... 16? It also seems strange that it reproducibly crashes or not depending on which specific font I use. On Tue,

[swift-users] Runtime crash caused by (NS)CharacterSet.hasMember?

2017-06-13 Thread Jens Persson via swift-users
The below program demonstrates a possible bug that I encountered. Can anyone else reproduce my results (as explained in the comments)? If so, is it a Swift or Cocoa bug (I haven't tried it in Objective C)? import AppKit extension NSFont { var planesWithMembers: [UInt8] { return

Re: [swift-users] Removed discussions in doc for Swift 4. Why?

2017-06-12 Thread Jens Persson via swift-users
"Removed discussion of variable function arguments and the special syntax for curried functions." On Mon, Jun 12, 2017 at 10:02 PM, tuuranton--- via swift-users < swift-users@swift.org> wrote: > > Austin Zheng wrote: > > > I'm not aware, though, of any proposal in the pipeline to remove variadic

Re: [swift-users] Removed discussions in doc for Swift 4. Why?

2017-06-12 Thread Jens Persson via swift-users
That is, "variable" not "variadic" function arguments. func foo(var a: Int) { ... } is no longer valid, the parameter may not have the var specifier anymore. On Mon, Jun 12, 2017 at 10:24 PM, Jens Persson wrote: > "Removed discussion of variable function arguments and the

Re: [swift-users] Multiple value-binding patterns in a single switch case

2017-06-09 Thread Jens Persson via swift-users
I'm not sure what you are trying to achieve. Why can't you just do: label.text = animal.nam ? Is it because not all Animals have names? If so, you could perhaps use something like this: class Animal {} protocol Named { var name: String { get } } class Dog: Animal, Named { let name = "Dog"

Re: [swift-users] Development Snapshots don't work with Xcode 9 beta?

2017-06-08 Thread Jens Persson via swift-users
Got the answer here: https://twitter.com/jckarter/status/872899857463205888 " If you're using http://swift.org snapshots with Xcode 9, `defaults write http://com.apple .dt.Xcode IDEIndexEnableBoltIndex NO` This disables indexing-while-building, which isn't yet supported by the open source

[swift-users] Development Snapshots don't work with Xcode 9 beta?

2017-06-08 Thread Jens Persson via swift-users
I can't use development snapshot toolchains in Xcode 9 beta. This is the error reported from the swiftc of the toolchain: :0: error: unknown argument: '-index-store-path' Is it a known issue? /Jens ___ swift-users mailing list swift-users@swift.org

Re: [swift-users] Swift 4 protocol with associatedtype conforming to itself

2017-06-07 Thread Jens Persson via swift-users
Ok, thanks! On Wed, Jun 7, 2017 at 4:52 PM, Karl Wagner <razie...@gmail.com> wrote: > > On 7. Jun 2017, at 11:29, Jens Persson via swift-users < > swift-users@swift.org> wrote: > > I see, this quote from the introduction of SE-0142 is not to be taken > l

Re: [swift-users] Swift 4 protocol with associatedtype conforming to itself

2017-06-07 Thread Jens Persson via swift-users
anyway). >> >> The proposal is here if you’d like to read more about it: >> https://github.com/apple/swift-evolution/blob/master/proposa >> ls/0157-recursive-protocol-constraints.md >> >> Slava >> >> > On Jun 6, 2017, at 10:37 PM, Jens Pe

Re: [swift-users] Swift 4 protocol with associatedtype conforming to itself

2017-06-07 Thread Jens Persson via swift-users
ft-evolution/blob/master/ > proposals/0157-recursive-protocol-constraints.md > > Slava > > > On Jun 6, 2017, at 10:37 PM, Jens Persson via swift-users < > swift-users@swift.org> wrote: > > > > In Swift 4: > > > > protocol P1 { > > associa

[swift-users] Swift 4 protocol with associatedtype conforming to itself

2017-06-06 Thread Jens Persson via swift-users
In Swift 4: protocol P1 { associatedtype A: P1 // Error: Type may not reference itself as a requirement } protocol P2 { associatedtype A where A: P2 // OK } What is the rationale behind this? /Jens ___ swift-users mailing list

Re: [swift-users] Compile time exceeded. Anything wrong?

2017-06-06 Thread Jens Persson via swift-users
mpile run too >> slow. It indeed a bug. Optimizing the code for the compiling time is >> really a headache for coders. I am using the Xcode 8.1. Hoping it can be >> fixed in next release. >> >> >> *best wishes for you * >> >> 2017-06-06 8:57 G

Re: [swift-users] arc4random_uniform on Linux is missing from Foundation??

2017-05-22 Thread Jens Persson via swift-users
Check out the generators (especially xoroshiro) on this site: On Mon, May 22, 2017 at 6:54 PM, Saagar Jha via swift-users < swift-users@swift.org> wrote: > > Saagar Jha > > On May 22, 2017, at 08:44, Edward Connell via swift-users < > swift-users@swift.org> wrote: > > Any ideas when Foundation

Re: [swift-users] arc4random_uniform on Linux is missing from Foundation??

2017-05-22 Thread Jens Persson via swift-users
Sorry for the premature send ... Here is the site: http://xoroshiro.di.unimi.it There is also a section there about "generating uniform doubles in unit interval" which is worth reading. And here's how to get uniform floating point values in the range [0, 1) from various (supposedly) random bit

Re: [swift-users] Splitting a string into "natural/visual character" components?

2017-05-12 Thread Jens Persson via swift-users
you can simply do something like > > Array("‍‍‍‍♀️".characters) > > once Unicode 9 is adopted in Swift. > > Regards, Martin > > > On 12. May 2017, at 10:43, Jens Persson via swift-users < > swift-users@swift.org> wrote: > > I want a function f

Re: [swift-users] Splitting a string into "natural/visual character" components?

2017-05-12 Thread Jens Persson via swift-users
FWIW: I can conclude that the third example does not render correctly in Gmail ... On Fri, May 12, 2017 at 10:43 AM, Jens Persson wrote: > I want a function f such that: > > f("abc") == ["a", "b", "c"] > > f("café") == ["c", "a", "f", "é"] > > f("‍‍‍‍♀️") == ["‍‍‍",

[swift-users] Splitting a string into "natural/visual character" components?

2017-05-12 Thread Jens Persson via swift-users
I want a function f such that: f("abc") == ["a", "b", "c"] f("café") == ["c", "a", "f", "é"] f("‍‍‍‍♀️") == ["‍‍‍", "‍♀️"] I'm not sure if the last example renders correctly by mail for everyone but the input String contains these _two_ "natural/visual characters": (1) A family

Re: [swift-users] Difficulties extending BinaryFloatingPoint

2017-01-05 Thread Jens Persson via swift-users
ic func _cos() -> Float { return cos(self) } > } > > func exp(_ x: T) -> T { return x._exp() } > func log(_ x: T) -> T { return x._log() } > func sin(_ x: T) -> T { return x._sin() } > func cos(_ x: T) -> T { return x._cos() } > > extension Math { > func sigm

[swift-users] Difficulties extending BinaryFloatingPoint

2017-01-05 Thread Jens Persson via swift-users
The code below doesn't compile since there is no exponential function (exp) that works on all FloatingPoint or BinaryFloatingPoint types, also no protocol seems to define the power function or the constant e, although they do define for example: basic arithmetic operators, squareRoot() and pi.

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

2017-01-04 Thread Jens Persson via swift-users
; > > let bigRect = CGRect(x: 0, y: 0, width: 10_000, height: 10_000) > > let iterator = profile(10) { iteratePoints_it(bigRect) { if $0.x > > 1_000_000 { print("?") } } } // always false, won't be optimised out. > let foreach = profile(10) { iteratePoints_fe(bi

[swift-users] NSFontManager's availableMembers(ofFontFamily: String) broken?

2016-10-08 Thread Jens Persson via swift-users
It crashes runtime except when the given string is not an existing font family name, in which case it returns nil (as expected). So I'm unable to use it. Here's a REPL session demo of the issue, but it's the same in Xcode 8 and 8.1 beta 1 (haven't tried any other versions): Welcome to Apple

Re: [swift-users] Swift REPL broken after updating to Sierra, is it just me?

2016-10-06 Thread Jens Persson via swift-users
gt; REPL. If that works, can you attach that history file to the Radar you > mentioned, so we can make sure this is the same history reading bug? > > Thanks, > > Jim > > > > On Oct 6, 2016, at 12:46 PM, Jens Persson via swift-users < > swift-users@swift.org> w

Re: [swift-users] Swift REPL broken after updating to Sierra, is it just me?

2016-10-06 Thread Jens Persson via swift-users
>> I can’t say I’ve seen a segmentation fault on REPL launch. If you see >> the same behavior once moving to the GM build of Xcode it would definitely >> be worth filing a radar via bugreport.apple.com with an LLDB crashlog >> attached to investigate further. >> >&g

Re: [swift-users] Swift REPL broken after updating to Sierra, is it just me?

2016-10-06 Thread Jens Persson via swift-users
ng to the GM build of Xcode it would definitely be > worth filing a radar via bugreport.apple.com with an LLDB crashlog > attached to investigate further. > > Kate Stone k8st...@apple.com >  Xcode Low Level Tools > > On Oct 6, 2016, at 6:51 AM, Jens Persson via swift-users <

Re: [swift-users] Performance critical code in Swift

2016-10-01 Thread Jens Persson via swift-users
You could write some examples in both C and Swift in order to gain experience in how to write your Swift code so that it will (probably) run as fast as (or faster than) your corresponding C code. I've done this for a number of different performance critical things and it is often possible to get

Re: [swift-users] Swift 3 and bytes

2016-09-25 Thread Jens Persson via swift-users
Use UnsafeMutableRawPointer. On Sun, Sep 25, 2016 at 1:28 PM, Gerriet M. Denkmann via swift-users < swift-users@swift.org> wrote: > Got: > var bitField : UnsafeMutablePointer > bitField = UnsafeMutablePointer< UInt32 >.allocate(capacity: 912) > > But now I want to read a certain range as bytes

Re: [swift-users] How to malloc in Swift 3

2016-09-23 Thread Jens Persson via swift-users
What is the difference between: ptr.storeBytes(of: x, toByteOffset: offset, as: type(of: x)) ptr.advanced(by: offset).assumingMemoryBound(to: type(of: x)).pointee = x ? I noticed that the former traps if storing to a misaligned offset while the latter is happy to do that, and I saw it mentioned as

Re: [swift-users] Can anyone please explain this behavior?

2016-09-22 Thread Jens Persson via swift-users
ng this up, if only so I have an opportunity to write > out the issue. :-) > > > Jordan > > > > > > > > >> On Sep 21, 2016, at 23:04, Jens Persson <j...@bitcycle.com> wrote: > > >> > > >> Did you see the other code examples th

Re: [swift-users] Can anyone please explain this behavior?

2016-09-22 Thread Jens Persson via swift-users
t; Did you see the other code examples that came up in that twitter >> conversations? >> For example: >> >> This worrying little program compiles: >> func f() -> Int { >> return a >> } >> let a = f() >> >> >> It also compiles if you

Re: [swift-users] Can anyone please explain this behavior?

2016-09-22 Thread Jens Persson via swift-users
t; > And also this: > > AnotherFile.swift containing: > func f() -> Int { > return a > } > let a = f() > > main.swift containing > print(a) > > Compile, run (for eternity, at 0% CPU). > > /Jens > > > On Thu, Sep 22, 2016 at 3:13

Re: [swift-users] Can anyone please explain this behavior?

2016-09-22 Thread Jens Persson via swift-users
21, 2016, at 2:22 PM, Jens Persson via swift-users < > swift-users@swift.org> wrote: > > > > // This little Swift program compiles (and runs) fine: > > > > func foo() -> Int { return a } > > let a = 1 > > let b = 2 > > print(foo()) > > >

Re: [swift-users] Can anyone please explain this behavior?

2016-09-21 Thread Jens Persson via swift-users
lthough from the global variable point of view, both way should be fine. > But the glitch does exist, especially in playground. > > Zhaoxin > > On Thu, Sep 22, 2016 at 5:59 AM, Marco S Hyman via swift-users < > swift-users@swift.org> wrote: > >> >> > On

[swift-users] Can anyone please explain this behavior?

2016-09-21 Thread Jens Persson via swift-users
// This little Swift program compiles (and runs) fine: func foo() -> Int { return a } let a = 1 let b = 2 print(foo()) But if `foo()` returns `b` instead of `a`, I get this compile time error: "Use of unresolved identifier `b`" ___ swift-users mailing