[swift-evolution] protocol-oriented integers (take 2)

Xiaodi Wu xiaodi.wu at gmail.com
Sun Jan 29 23:13:05 CST 2017

I share your concern about trailingZeros and leadingZeros; those could
probably be improved as trailingZeroBits and leadingZeroBits. The terms of
art there, ctz ("count trailing zeros") and clz, are a bit cryptic but
perhaps also fine if ulp is acceptable for FloatingPoint.

On Sun, Jan 29, 2017 at 22:42 Brent Royal-Gordon via swift-evolution <
swift-evolution at swift.org> wrote:

> > On Jan 29, 2017, at 7:02 PM, Dave Abrahams via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> >>>  var popcount: Int { get }
> >>
> >> I'm not super-fond of this name; I assume it's a term of art, but it's
> >> a pretty obscure one. Maybe `numberOfOnes`? `onesWithin`?
> >
> > Yes, the rationale is that it's a term of art.  I think if you were
> > going to call it something else, you'd need to mention "one _bits_" in
> > the name.  If we can come up with a name that's obviously better, that's
> > great, but lacking a clear winner we should go with the already-accepted
> > term.
> Okay, but the same could be said for `trailingZeros`. Does that also need
> to be something like `trailingZerosInBinaryRepresentation` or what-have-you?
> >> It might make a great deal of sense to support bitwise operations on
> >> this type,
> >
> > I think that's a model of SetAlgebra, then, isn't it?
> Hmm, arguably. It's a shame that we won't be able to use it with things
> like `OptionSet`, though.
> > Personally I don't think the strict separation of SetAlgebra and things
> > that do bitwise operations makes sense, but I know some people feel
> > strongly that it would be confusing for users to expose set operations
> > with bitwise operator names.  IMO using | for union and & for
> > intersection would be beautiful.  But that's a story for another day...
> Honestly, if I were designing Swift from scratch, I might consider having
> a `BitView` type and `bits` member which acts as a collection of `Bool`s
> (or maybe a set of offsets of `1` bits?) and conforms to `SetAlgebra`; you
> could then perform bitwise operations through the `bits`, but not directly
> on the value itself. But that ship has clearly sailed.
> --
> Brent Royal-Gordon
> Architechies
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170130/982350f4/attachment.html>

More information about the swift-evolution mailing list