Re: [swift-evolution] Working with enums by name

2016-06-02 Thread Leonardo Pessoa via swift-evolution
;; "swift-evolution" <swift-evolution@swift.org> Subject: Re: [swift-evolution] Working with enums by name >From what I understand, enums normally are represented internally by an offset >— that is their truth. With RawRepresentable enums, you are saying “no, I want >the

Re: [swift-evolution] Working with enums by name

2016-06-02 Thread Patrick Smith via swift-evolution
essoa.com>; swift-evolution > <mailto:swift-evolution@swift.org> > Subject: Re: [swift-evolution] Working with enums by name > > Great points Brent. I think the ValuesEnumerable method would be the most > straight forward. Also, the number of cases are likely only going

Re: [swift-evolution] Working with enums by name

2016-06-02 Thread Leonardo Pessoa via swift-evolution
worked with. L -Original Message- From: "Patrick Smith" <pgwsm...@gmail.com> Sent: ‎02/‎06/‎2016 02:07 AM To: "Brent Royal-Gordon" <br...@architechies.com> Cc: "Leonardo Pessoa" <m...@lmpessoa.com>; "swift-evolution" <swif

Re: [swift-evolution] Working with enums by name

2016-06-02 Thread Leonardo Pessoa via swift-evolution
you're using them). L -Original Message- From: "Brent Royal-Gordon" <br...@architechies.com> Sent: ‎02/‎06/‎2016 01:40 AM To: "Leonardo Pessoa" <m...@lmpessoa.com> Cc: "Vladimir.S" <sva...@gmail.com>; "swift-evolution" <swif

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Brent Royal-Gordon via swift-evolution
> Brent, for needing "both Int and Double values" there is a proposal to add > tuples instead of the current raw values or allowing assessor properties per > case, you should check those out. Perhaps this could also be used to > cryptoghaphically sign a raw value but I'm not sure. I know; I

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Leonardo Pessoa via swift-evolution
ion" <swift-evolution@swift.org> Subject: Re: [swift-evolution] Working with enums by name > This should work but feels like an ugly hack to me. What if I needed > the enum like this? > > | enum Size : Double { > | case Fit = 0.5 > | case Fill = 3.0 > |

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Vladimir.S via swift-evolution
Can't agree with Brent's opinion. For me the proposed init(caseName:String) and .caseName property for enum case - seems like base feature that enum type must to have. As for string as raw value for enum, please find this example: enum E: String { case one = "One" case two = "Two" }

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Christopher Kornher via swift-evolution
Oops. I have wanted this feature and I have created `name` methods for non-String enums numerous times (whether I had to or not, I guess). If there is a formal proposal for this, I could not find it. I am obviously not familiar with the entire proposal but this is a feature that I have wanted

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Brent Royal-Gordon via swift-evolution
> This should work but feels like an ugly hack to me. What if I needed > the enum like this? > > | enum Size : Double { > | case Fit = 0.5 > | case Fill = 3.0 > | } What if you needed both Int and Double rawValues? What if you needed rawValues that were cryptographically signed?

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Paul Cantrell via swift-evolution
> On Jun 1, 2016, at 2:20 PM, Christopher Kornher via swift-evolution > > wrote: > >> On Jun 1, 2016, at 12:53 PM, Paul Cantrell via swift-evolution >> > wrote: >> >> This

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Leonardo Pessoa via swift-evolution
Enums outside frameworks will still rely on you as the programmer to know to which enum the string representation belongs to (it does so for the raw values) so I see no reason why the .caseName result should have the name of any underlying type the case belongs to. L On 1 June 2016 at 16:20,

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Christopher Kornher via swift-evolution
> On Jun 1, 2016, at 12:53 PM, Paul Cantrell via swift-evolution > wrote: > > Indeed, you’re quite right: verified that I get “Mars” even when the enum is > in a framework. > > It took a little digging to get back what I was thinking of: it’s when the > enum value

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Paul Cantrell via swift-evolution
Indeed, you’re quite right: verified that I get “Mars” even when the enum is in a framework. It took a little digging to get back what I was thinking of: it’s when the enum value is inside some other data structure that you get an annoyingly fully qualified name: enum CoinSide {

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Vladimir.S via swift-evolution
This will not print the name of case : enum E: CustomStringConvertible { case one, two var description: String {return "haha"} } print(E.one) So, for me, it seems like the good idea to have a standard(and built-in) way to convert string<->case i.e. to have let e = E(caseName:

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Paul Cantrell via swift-evolution
IIRC, string interpolation prepends the module name if the enum belongs to a module: “MyLib.Mars” instead of just “Mars”. It’s also been a source of compiler crashes, at least in the past. Those two factors forced me into this ugliness:

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Leonardo Pessoa via swift-evolution
interpolation and need to do everything by hand the other way around. >> >> L >> >> --- >> From: Charlie Monroe via swift-evolution >> <mailto:swift-evolution@swift.org> >> Sent: ‎01/‎06/‎2016 07:19 AM >> To: Brent Royal-Gordon <mailto:br...@arch

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Vladimir.S via swift-evolution
ift-evolution@swift.org> Sent: ‎01/‎06/‎2016 07:19 AM To: Brent Royal-Gordon <mailto:br...@architechies.com> Cc: Swift-evolution <mailto:swift-evolution@swift.org> Subject: Re: [swift-evolution] Working with enums by name Sorry, must've missed that. On Jun 1, 2016, at 12:17 PM, Bren

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Leonardo Pessoa via swift-evolution
the other way around. L -Original Message- From: "Charlie Monroe via swift-evolution" <swift-evolution@swift.org> Sent: ‎01/‎06/‎2016 07:19 AM To: "Brent Royal-Gordon" <br...@architechies.com> Cc: "Swift-evolution" <swift-evolution@swif

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Leonardo Pessoa via swift-evolution
ies.com> Cc: "Swift-evolution" <swift-evolution@swift.org> Subject: Re: [swift-evolution] Working with enums by name Sorry, must've missed that. > On Jun 1, 2016, at 12:17 PM, Brent Royal-Gordon <br...@architechies.com> > wrote: > >> This is, however, ki

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Charlie Monroe via swift-evolution
Sorry, must've missed that. > On Jun 1, 2016, at 12:17 PM, Brent Royal-Gordon > wrote: > >> This is, however, kind of a hack IMHO that relies on the compiler behavior >> that isn't well documented. > > It's documented in "The Swift Programming Language", in the same

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Brent Royal-Gordon via swift-evolution
This is, however, kind of a hack IMHO that relies on the compiler behavior that isn't well documented.It's documented in "The Swift Programming Language", in the same paragraphs where the `enum Planet` example we've been working with comes from.“When you’re working with enumerations that store

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Charlie Monroe via swift-evolution
This is, however, kind of a hack IMHO that relies on the compiler behavior that isn't well documented. For example, this: enum Planet { case Earth case Mars } "\(Planet.Mars)" // This is "Mars" Works as well. You don't need to have the represented value to be String. Note

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Leonardo Pessoa via swift-evolution
...@gmail.com> Sent: ‎01/‎06/‎2016 04:52 AM To: "Brent Royal-Gordon" <br...@architechies.com> Cc: "Leonardo Pessoa" <m...@lmpessoa.com>; "Swift-evolution" <swift-evolution@swift.org> Subject: Re: [swift-evolution] Working with enums by name I had

Re: [swift-evolution] Working with enums by name

2016-06-01 Thread Patrick Smith via swift-evolution
I had no idea you could do this!! > On 1 Jun 2016, at 12:32 PM, Brent Royal-Gordon via swift-evolution > wrote: > > Who said anything about repeating the name? > > Welcome to Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.30). > Type :help for

Re: [swift-evolution] Working with enums by name

2016-05-31 Thread Brent Royal-Gordon via swift-evolution
> Don't you think it's a bit of a waste to be repeating the name of the value > as a string just to use init(rawValue:) with them? Who said anything about repeating the name? Welcome to Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.30). Type :help for assistance. 1> enum Planet:

Re: [swift-evolution] Working with enums by name

2016-05-31 Thread Leonardo Pessoa via swift-evolution
If I got the idea right, you would need to implement yourself the protocol methods to answer for both init(rawValue: Int) and init(rawValue: String) - which is how you have to do today only with the string part - while my proposed approach you'd have to implement nothing yourself. L > On 31

Re: [swift-evolution] Working with enums by name

2016-05-31 Thread Leonardo Pessoa via swift-evolution
Don't you think it's a bit of a waste to be repeating the name of the value as a string just to use init(rawValue:) with them? What if I need to store another string associated with the value of the enum e.g. I want to create an enum to represent options in a menu and the associated value is to

Re: [swift-evolution] Working with enums by name

2016-05-31 Thread Erica Sadun via swift-evolution
> On May 31, 2016, at 4:07 PM, Brent Royal-Gordon via swift-evolution > wrote: > >> • also wants OptionSetType-like behavior (and thus an Int raw type). > > Then it's not an `enum`, it's a `struct`. You can get it for free as an array of enums and test with

Re: [swift-evolution] Working with enums by name

2016-05-31 Thread Brent Royal-Gordon via swift-evolution
> • also wants OptionSetType-like behavior (and thus an Int raw type). Then it's not an `enum`, it's a `struct`. -- Brent Royal-Gordon Architechies ___ swift-evolution mailing list swift-evolution@swift.org

Re: [swift-evolution] Working with enums by name

2016-05-31 Thread Paul Cantrell via swift-evolution
> On May 31, 2016, at 4:48 PM, Brent Royal-Gordon via swift-evolution > wrote: > >> | enum Planet : Int { >> | case Mercury = 1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune >> | >> | init?(caseName name : String) { > > The compiler actually does

[swift-evolution] Working with enums by name

2016-05-31 Thread Leonardo Pessoa via swift-evolution
Since we're talking a lot enums these days, I'd like to bring into discussion a proposal that has been briefly mentioned in another thread to enable working with enums using their names. This is currently possible in the language but it's a bit burdensome. You can just interpolate the value of